annotate scripts/time/datestr.m @ 14237:11949c9795a0

Revamp %!demos in m-files to use Octave coding conventions on spacing, etc. Add clf() to all demos using plot features to get reproducibility. Use 64 as input to all colormaps (jet (64)) to get reproducibility. * bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m, interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m, griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m, copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m, ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m, condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m, compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m, ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m, ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m, fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m, pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m, plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m, rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m, semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m, subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m, triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m, waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m, bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m, example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m, weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author Rik <octave@nomad.inbox5.com>
date Fri, 20 Jan 2012 12:59:53 -0800
parents 72c96de7a403
children 3fd6f637c573
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13856
diff changeset
1 ## Copyright (C) 2000-2012 Paul Kienzle
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
2 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
4 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
8 ## your option) any later version.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
9 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
14 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6555
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
18
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11329
diff changeset
20 ## @deftypefn {Function File} {@var{str} =} datestr (@var{date})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11329
diff changeset
21 ## @deftypefnx {Function File} {@var{str} =} datestr (@var{date}, @var{f})
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 11329
diff changeset
22 ## @deftypefnx {Function File} {@var{str} =} datestr (@var{date}, @var{f}, @var{p})
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
23 ## Format the given date/time according to the format @code{f} and return
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 ## the result in @var{str}. @var{date} is a serial date number (see
6555
69e864d21c11 [project @ 2007-04-20 18:16:08 by jwe]
jwe
parents: 6046
diff changeset
25 ## @code{datenum}) or a date vector (see @code{datevec}). The value of
69e864d21c11 [project @ 2007-04-20 18:16:08 by jwe]
jwe
parents: 6046
diff changeset
26 ## @var{date} may also be a string or cell array of strings.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
27 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
28 ## @var{f} can be an integer which corresponds to one of the codes in
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
29 ## the table below, or a date format string.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
30 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
31 ## @var{p} is the year at the start of the century in which two-digit years
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
32 ## are to be interpreted in. If not specified, it defaults to the current
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
33 ## year minus 50.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
34 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
35 ## For example, the date 730736.65149 (2000-09-07 15:38:09.0934) would be
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
36 ## formatted as follows:
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
37 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
38 ## @multitable @columnfractions 0.1 0.45 0.35
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
39 ## @headitem Code @tab Format @tab Example
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
40 ## @item 0 @tab dd-mmm-yyyy HH:MM:SS @tab 07-Sep-2000 15:38:09
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
41 ## @item 1 @tab dd-mmm-yyyy @tab 07-Sep-2000
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
42 ## @item 2 @tab mm/dd/yy @tab 09/07/00
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
43 ## @item 3 @tab mmm @tab Sep
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
44 ## @item 4 @tab m @tab S
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
45 ## @item 5 @tab mm @tab 09
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
46 ## @item 6 @tab mm/dd @tab 09/07
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
47 ## @item 7 @tab dd @tab 07
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
48 ## @item 8 @tab ddd @tab Thu
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
49 ## @item 9 @tab d @tab T
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
50 ## @item 10 @tab yyyy @tab 2000
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
51 ## @item 11 @tab yy @tab 00
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
52 ## @item 12 @tab mmmyy @tab Sep00
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
53 ## @item 13 @tab HH:MM:SS @tab 15:38:09
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
54 ## @item 14 @tab HH:MM:SS PM @tab 03:38:09 PM
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
55 ## @item 15 @tab HH:MM @tab 15:38
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
56 ## @item 16 @tab HH:MM PM @tab 03:38 PM
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
57 ## @item 17 @tab QQ-YY @tab Q3-00
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
58 ## @item 18 @tab QQ @tab Q3
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
59 ## @item 19 @tab dd/mm @tab 13/03
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
60 ## @item 20 @tab dd/mm/yy @tab 13/03/95
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
61 ## @item 21 @tab mmm.dd.yyyy HH:MM:SS @tab Mar.03.1962 13:53:06
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
62 ## @item 22 @tab mmm.dd.yyyy @tab Mar.03.1962
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
63 ## @item 23 @tab mm/dd/yyyy @tab 03/13/1962
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
64 ## @item 24 @tab dd/mm/yyyy @tab 12/03/1962
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
65 ## @item 25 @tab yy/mm/dd @tab 95/03/13
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
66 ## @item 26 @tab yyyy/mm/dd @tab 1995/03/13
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
67 ## @item 27 @tab QQ-YYYY @tab Q4-2132
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
68 ## @item 28 @tab mmmyyyy @tab Mar2047
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
69 ## @item 29 @tab yyyymmdd @tab 20470313
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
70 ## @item 30 @tab yyyymmddTHHMMSS @tab 20470313T132603
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
71 ## @item 31 @tab yyyy-mm-dd HH:MM:SS @tab 1047-03-13 13:26:03
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
72 ## @end multitable
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
73 ##
9079
4d610aba7347 Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
74 ## If @var{f} is a format string, the following symbols are recognized:
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
75 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
76 ## @multitable @columnfractions 0.1 0.7 0.2
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
77 ## @headitem Symbol @tab Meaning @tab Example
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
78 ## @item yyyy @tab Full year @tab 2005
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
79 ## @item yy @tab Two-digit year @tab 2005
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
80 ## @item mmmm @tab Full month name @tab December
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
81 ## @item mmm @tab Abbreviated month name @tab Dec
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
82 ## @item mm @tab Numeric month number (padded with zeros) @tab 01, 08, 12
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
83 ## @item m @tab First letter of month name (capitalized) @tab D
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
84 ## @item dddd @tab Full weekday name @tab Sunday
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
85 ## @item ddd @tab Abbreviated weekday name @tab Sun
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
86 ## @item dd @tab Numeric day of month (padded with zeros) @tab 11
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
87 ## @item d @tab First letter of weekday name (capitalized) @tab S
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
88 ## @item HH @tab Hour of day, padded with zeros if PM is set @tab 09:00
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
89 ## @item @tab and not padded with zeros otherwise @tab 9:00 AM
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
90 ## @item MM @tab Minute of hour (padded with zeros) @tab 10:05
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
91 ## @item SS @tab Second of minute (padded with zeros) @tab 10:05:03
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
92 ## @item FFF @tab Milliseconds of second (padded with zeros) @tab 10:05:03.012
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
93 ## @item AM @tab Use 12-hour time format @tab 11:30 AM
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
94 ## @item PM @tab Use 12-hour time format @tab 11:30 PM
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
95 ## @end multitable
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
96 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
97 ## If @var{f} is not specified or is @code{-1}, then use 0, 1 or 16,
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
98 ## depending on whether the date portion or the time portion of
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
99 ## @var{date} is empty.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
100 ##
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
101 ## If @var{p} is nor specified, it defaults to the current year minus 50.
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
102 ##
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
103 ## If a matrix or cell array of dates is given, a column vector of date strings
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
104 ## is returned.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
105 ##
13856
d490ca8ab1a5 Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents: 13848
diff changeset
106 ## @seealso{datenum, datevec, date, now, clock}
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
107 ## @end deftypefn
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
108
8202
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
109 ## FIXME: parse arbitrary code strings.
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
110 ## e.g., for Wednesday 2001-03-05 09:04:06 AM, use
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
111 ## yy 01
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
112 ## yyyy 2001
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
113 ## m M
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
114 ## mm 03
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
115 ## mmm Mar
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
116 ## d W
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
117 ## dd 05
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
118 ## ddd Wed
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
119 ## HH 09
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
120 ## MM 04
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
121 ## SS 06
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
122 ## PM AM
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
123 ## FIXME: Vectorize. It is particularly easy since all the codes are
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
124 ## fixed width. Just generate the parts in separate arrays and
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 8112
diff changeset
125 ## concatenate.
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
126
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
127 ## Author: pkienzle <pkienzle@users.sf.net>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
128 ## Created: 10 October 2001 (CVS)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
129 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com>
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
130
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
131 function retval = datestr (date, f = [], p = [])
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
132
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
133 persistent dateform names_mmmm names_m names_d;
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
134
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
135 if (isempty (dateform))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
136 dateform = cell (32, 1);
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
137 dateform{1} = "dd-mmm-yyyy HH:MM:SS";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
138 dateform{2} = "dd-mmm-yyyy";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
139 dateform{3} = "mm/dd/yy";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
140 dateform{4} = "mmm";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
141 dateform{5} = "m";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
142 dateform{6} = "mm";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
143 dateform{7} = "mm/dd";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
144 dateform{8} = "dd";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
145 dateform{9} = "ddd";
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
146 dateform{10} = "d";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
147 dateform{11} = "yyyy";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
148 dateform{12} = "yy";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
149 dateform{13} = "mmmyy";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
150 dateform{14} = "HH:MM:SS";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
151 dateform{15} = "HH:MM:SS PM";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
152 dateform{16} = "HH:MM";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
153 dateform{17} = "HH:MM PM";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
154 dateform{18} = "QQ-YY";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
155 dateform{19} = "QQ";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
156 dateform{20} = "dd/mm";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
157 dateform{21} = "dd/mm/yy";
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
158 dateform{22} = "mmm.dd,yyyy HH:MM:SS";
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
159 dateform{23} = "mmm.dd,yyyy";
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
160 dateform{24} = "mm/dd/yyyy";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
161 dateform{25} = "dd/mm/yyyy";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
162 dateform{26} = "yy/mm/dd";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
163 dateform{27} = "yyyy/mm/dd";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
164 dateform{28} = "QQ-YYYY";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
165 dateform{29} = "mmmyyyy";
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
166 dateform{30} = "yyyy-mm-dd";
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
167 dateform{31} = "yyyymmddTHHMMSS";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
168 dateform{32} = "yyyy-mm-dd HH:MM:SS";
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
169
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
170 names_m = {"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"};
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
171 names_d = {"S", "M", "T", "W", "T", "F", "S"};
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
172 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
173
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
174 if (nargin < 1 || nargin > 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5687
diff changeset
175 print_usage ();
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
176 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
177
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
178 ## Guess input type. We might be wrong.
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
179 if (ischar (date) || iscellstr (date) || columns (date) != 6)
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
180 v = datevec (date, p);
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
181 else
7492
bd1168732c95 datestr.m: fix 6 datenum vector bug
bill@denney.ws
parents: 7017
diff changeset
182 v = [];
7493
f1bce8450fd0 [mq]: tmp-patch
John W. Eaton <jwe@octave.org>
parents: 7492
diff changeset
183 if (columns (date) == 6)
f1bce8450fd0 [mq]: tmp-patch
John W. Eaton <jwe@octave.org>
parents: 7492
diff changeset
184 ## Make sure that the input really is a datevec.
f1bce8450fd0 [mq]: tmp-patch
John W. Eaton <jwe@octave.org>
parents: 7492
diff changeset
185 maxdatevec = [Inf, 12, 31, 23, 59, 60];
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
186 if (any (max (date, 1) > maxdatevec) ||
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
187 any (date(:,1:5) != floor (date(:,1:5))))
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
188 v = datevec (date, p);
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
189 endif
7492
bd1168732c95 datestr.m: fix 6 datenum vector bug
bill@denney.ws
parents: 7017
diff changeset
190 endif
7493
f1bce8450fd0 [mq]: tmp-patch
John W. Eaton <jwe@octave.org>
parents: 7492
diff changeset
191 if (isempty (v))
7492
bd1168732c95 datestr.m: fix 6 datenum vector bug
bill@denney.ws
parents: 7017
diff changeset
192 v = date;
bd1168732c95 datestr.m: fix 6 datenum vector bug
bill@denney.ws
parents: 7017
diff changeset
193 endif
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
194 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
195
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
196 retval = [];
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
197 for i = 1 : rows (v)
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
198
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
199 if (isempty (f))
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
200 if (v(i,4:6) == 0)
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
201 f = 1;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
202 elseif (v(i,1:3) == [-1, 12, 31])
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
203 f = 16;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
204 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
205 f = 0;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
206 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
207 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
208
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
209 if (isnumeric (f))
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
210 df = dateform{f + 1};
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
211 else
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
212 df = f;
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
213 endif
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
214
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
215 df_orig = df;
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
216 df = strrep (df, 'AM', "%p");
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
217 df = strrep (df, 'PM', "%p");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
218 if (strcmp (df, df_orig))
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
219 ## PM not set.
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
220 df = strrep (df, "HH", "%H");
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
221 else
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
222 df = strrep (df, "HH", sprintf ("%2d", v(i,4)));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
223 endif
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
224
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
225 df = regexprep (df, '[Yy][Yy][Yy][Yy]', "%Y");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
226
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
227 df = regexprep (df, '[Yy][Yy]', "%y");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
228
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
229 df = regexprep (df, '[Dd][Dd][Dd][Dd]', "%A");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
230
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
231 df = regexprep (df, '[Dd][Dd][Dd]', "%a");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
232
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
233 df = regexprep (df, '[Dd][Dd]', "%d");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
234
11328
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
235 wday = weekday (datenum (v(i,1), v(i,2), v(i,3)));
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
236 tmp = names_d{wday};
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
237 df = regexprep (df, '([^%])[Dd]', sprintf ("$1%s", tmp));
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
238 df = regexprep (df, '^[Dd]', sprintf ("%s", tmp));
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
239
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
240 df = strrep (df, "mmmm", "%B");
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
241
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
242 df = strrep (df, "mmm", "%b");
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
243
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
244 df = strrep (df, "mm", "%m");
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
245
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
246 tmp = names_m{v(i,2)};
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
247 pos = regexp (df, '[^%]m') + 1;
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
248 df(pos) = tmp;
11032
c9b0a75b02e8 Make all regexp in Octave compatible with both POSIX and PCRE.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
249 df = regexprep (df, '^m', tmp);
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
250
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
251 df = strrep (df, "MM", "%M");
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
252
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
253 df = regexprep (df, '[Ss][Ss]', "%S");
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
254
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
255 df = strrep (df, "FFF", sprintf ("%03d", 1000 * (v(i,6) - fix (v(i,6)))));
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
256
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
257 df = strrep (df, 'QQ', sprintf ("Q%d", fix ((v(i,2) + 2) / 3)));
8098
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
258
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
259 vi = v(i,:);
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
260 tm.year = vi(1) - 1900;
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
261 tm.mon = vi(2) - 1;
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
262 tm.mday = vi(3);
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
263 tm.hour = vi(4);
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
264 tm.min = vi(5);
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
265 sec = vi(6);
229bd50e6e8f datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents: 7969
diff changeset
266 tm.sec = fix (sec);
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
267 tm.usec = fix ((sec - tm.sec) * 1e6);
11328
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
268 tm.wday = wday - 1;
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
269 ## FIXME -- Do we need YDAY and DST? How should they be computed?
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
270 ## We don't want to use "localtime (mktime (tm))" because that
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
271 ## doesn't correctly handle dates before 1970-01-01 on some systems.
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
272 ## tm.yday = ?;
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
273 ## tm.isdst = ?;
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
274
f286a874617c datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents: 11149
diff changeset
275 str = strftime (df, tm);
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
276
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
277 retval = [retval; str];
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
278
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
279 endfor
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
280
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
281 endfunction
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
282
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
283
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
284 %!demo
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
285 %! ## Current date and time in default format
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
286 %! datestr (now ())
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
287
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
288 %!demo
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
289 %! ## Current date (integer portion of datenum)
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
290 %! datestr (fix (now ()))
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
291
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
292 %!demo
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
293 %! ## Current time (fractional portion of datenum)
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
294 %! datestr (rem (now (), 1))
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
295
5687
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
296 %!shared testtime
a2902024bc4e [project @ 2006-03-16 20:22:40 by jwe]
jwe
parents:
diff changeset
297 %! testtime = [2005.0000, 12.0000, 18.0000, 2.0000, 33.0000, 17.3822];
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
298 %!assert (datestr (testtime,0), "18-Dec-2005 02:33:17")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
299 %!assert (datestr (testtime,1), "18-Dec-2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
300 %!assert (datestr (testtime,2), "12/18/05")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
301 %!assert (datestr (testtime,3), "Dec")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
302 %!assert (datestr (testtime,4), "D")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
303 %!assert (datestr (testtime,5), "12")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
304 %!assert (datestr (testtime,6), "12/18")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
305 %!assert (datestr (testtime,7), "18")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
306 %!assert (datestr (testtime,8), "Sun")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
307 %!assert (datestr (testtime,9), "S")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
308 %!assert (datestr (testtime,10), "2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
309 %!assert (datestr (testtime,11), "05")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
310 %!assert (datestr (testtime,12), "Dec05")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
311 %!assert (datestr (testtime,13), "02:33:17")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
312 %!assert (datestr (testtime,14), " 2:33:17 AM")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
313 %!assert (datestr (testtime,15), "02:33")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
314 %!assert (datestr (testtime,16), " 2:33 AM")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
315 %!assert (datestr (testtime,17), "Q4-05")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
316 %!assert (datestr (testtime,18), "Q4")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
317 %!assert (datestr (testtime,19), "18/12")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
318 %!assert (datestr (testtime,20), "18/12/05")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
319 %!assert (datestr (testtime,21), "Dec.18,2005 02:33:17")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
320 %!assert (datestr (testtime,22), "Dec.18,2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
321 %!assert (datestr (testtime,23), "12/18/2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
322 %!assert (datestr (testtime,24), "18/12/2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
323 %!assert (datestr (testtime,25), "05/12/18")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
324 %!assert (datestr (testtime,26), "2005/12/18")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
325 %!assert (datestr (testtime,27), "Q4-2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
326 %!assert (datestr (testtime,28), "Dec2005")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
327 %!assert (datestr (testtime,29), "2005-12-18")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
328 %!assert (datestr (testtime,30), "20051218T023317")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
329 %!assert (datestr (testtime,31), "2005-12-18 02:33:17")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
330 %!assert (datestr (testtime+[0 0 3 0 0 0], "dddd"), "Wednesday")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
331 ## Test possible bug where input is a vector of datenums that is exactly 6 wide
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
332 %!assert (datestr ([1944, 6, 6, 6, 30, 0], 0), "06-Jun-1944 06:30:00")
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
333 ## Test fractional millisecond time extension
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
334 %!assert (datestr (testtime, "HH:MM:SS:FFF"), "02:33:17:382")
11329
6b073da9d7fc ChangeLog fix and new datestr test omitted from previous change
John W. Eaton <jwe@octave.org>
parents: 11328
diff changeset
335
13848
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
336 %% Test input validation
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
337 %!error datestr ()
40e32fe44aaa Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
338 %!error datestr (1, 2, 3, 4)
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
339