Mercurial > hg > octave-nkf
annotate scripts/time/datestr.m @ 10509:ddbd812d09aa
properly compress sparse matrices after assembly
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 12 Apr 2010 12:57:44 +0200 |
parents | 1393896df3b3 |
children | 95c3e38098bf |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, |
2 ## 2009 Paul Kienzle | |
5687 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
5687 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
5687 | 19 |
20 ## -*- texinfo -*- | |
21 ## @deftypefn {Function File} {@var{str} =} datestr (@var{date}, [@var{f}, [@var{p}]]) | |
22 ## 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
|
23 ## the result in @var{str}. @var{date} is a serial date number (see |
6555 | 24 ## @code{datenum}) or a date vector (see @code{datevec}). The value of |
25 ## @var{date} may also be a string or cell array of strings. | |
5687 | 26 ## |
27 ## @var{f} can be an integer which corresponds to one of the codes in | |
28 ## the table below, or a date format string. | |
29 ## | |
30 ## @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
|
31 ## are to be interpreted in. If not specified, it defaults to the current |
5687 | 32 ## year minus 50. |
33 ## | |
34 ## For example, the date 730736.65149 (2000-09-07 15:38:09.0934) would be | |
35 ## formatted as follows: | |
36 ## | |
37 ## @multitable @columnfractions 0.1 0.45 0.35 | |
38 ## @headitem Code @tab Format @tab Example | |
39 ## @item 0 @tab dd-mmm-yyyy HH:MM:SS @tab 07-Sep-2000 15:38:09 | |
40 ## @item 1 @tab dd-mmm-yyyy @tab 07-Sep-2000 | |
41 ## @item 2 @tab mm/dd/yy @tab 09/07/00 | |
42 ## @item 3 @tab mmm @tab Sep | |
43 ## @item 4 @tab m @tab S | |
44 ## @item 5 @tab mm @tab 09 | |
45 ## @item 6 @tab mm/dd @tab 09/07 | |
46 ## @item 7 @tab dd @tab 07 | |
47 ## @item 8 @tab ddd @tab Thu | |
48 ## @item 9 @tab d @tab T | |
49 ## @item 10 @tab yyyy @tab 2000 | |
50 ## @item 11 @tab yy @tab 00 | |
51 ## @item 12 @tab mmmyy @tab Sep00 | |
52 ## @item 13 @tab HH:MM:SS @tab 15:38:09 | |
53 ## @item 14 @tab HH:MM:SS PM @tab 03:38:09 PM | |
54 ## @item 15 @tab HH:MM @tab 15:38 | |
55 ## @item 16 @tab HH:MM PM @tab 03:38 PM | |
56 ## @item 17 @tab QQ-YY @tab Q3-00 | |
57 ## @item 18 @tab QQ @tab Q3 | |
58 ## @item 19 @tab dd/mm @tab 13/03 | |
59 ## @item 20 @tab dd/mm/yy @tab 13/03/95 | |
60 ## @item 21 @tab mmm.dd.yyyy HH:MM:SS @tab Mar.03.1962 13:53:06 | |
61 ## @item 22 @tab mmm.dd.yyyy @tab Mar.03.1962 | |
62 ## @item 23 @tab mm/dd/yyyy @tab 03/13/1962 | |
63 ## @item 24 @tab dd/mm/yyyy @tab 12/03/1962 | |
64 ## @item 25 @tab yy/mm/dd @tab 95/03/13 | |
65 ## @item 26 @tab yyyy/mm/dd @tab 1995/03/13 | |
66 ## @item 27 @tab QQ-YYYY @tab Q4-2132 | |
67 ## @item 28 @tab mmmyyyy @tab Mar2047 | |
68 ## @item 29 @tab yyyymmdd @tab 20470313 | |
69 ## @item 30 @tab yyyymmddTHHMMSS @tab 20470313T132603 | |
70 ## @item 31 @tab yyyy-mm-dd HH:MM:SS @tab 1047-03-13 13:26:03 | |
71 ## @end multitable | |
72 ## | |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
73 ## If @var{f} is a format string, the following symbols are recognized: |
5687 | 74 ## |
75 ## @multitable @columnfractions 0.1 0.7 0.2 | |
76 ## @headitem Symbol @tab Meaning @tab Example | |
77 ## @item yyyy @tab Full year @tab 2005 | |
78 ## @item yy @tab Two-digit year @tab 2005 | |
79 ## @item mmmm @tab Full month name @tab December | |
80 ## @item mmm @tab Abbreviated month name @tab Dec | |
81 ## @item mm @tab Numeric month number (padded with zeros) @tab 01, 08, 12 | |
82 ## @item m @tab First letter of month name (capitalized) @tab D | |
83 ## @item dddd @tab Full weekday name @tab Sunday | |
84 ## @item ddd @tab Abbreviated weekday name @tab Sun | |
85 ## @item dd @tab Numeric day of month (padded with zeros) @tab 11 | |
86 ## @item d @tab First letter of weekday name (capitalized) @tab S | |
87 ## @item HH @tab Hour of day, padded with zeros if PM is set @tab 09:00 | |
88 ## @item @tab and not padded with zeros otherwise @tab 9:00 AM | |
89 ## @item MM @tab Minute of hour (padded with zeros) @tab 10:05 | |
90 ## @item SS @tab Second of minute (padded with zeros) @tab 10:05:03 | |
91 ## @item PM @tab Use 12-hour time format @tab 11:30 PM | |
92 ## @end multitable | |
93 ## | |
94 ## If @var{f} is not specified or is @code{-1}, then use 0, 1 or 16, | |
95 ## depending on whether the date portion or the time portion of | |
96 ## @var{date} is empty. | |
97 ## | |
98 ## If @var{p} is nor specified, it defaults to the current year minus 50. | |
99 ## | |
100 ## If a matrix or cell array of dates is given, a vector of date strings is | |
101 ## returned. | |
102 ## | |
103 ## @seealso{datenum, datevec, date, clock, now, datetick} | |
104 ## @end deftypefn | |
105 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
106 ## FIXME: parse arbitrary code strings. |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
107 ## 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
|
108 ## yy 01 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
109 ## yyyy 2001 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
110 ## m M |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
111 ## mm 03 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
112 ## mmm Mar |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
113 ## d W |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
114 ## dd 05 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
115 ## ddd Wed |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
116 ## HH 09 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
117 ## MM 04 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
118 ## SS 06 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
119 ## PM AM |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
120 ## 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
|
121 ## 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
|
122 ## concatenate. |
5687 | 123 |
124 ## Author: pkienzle <pkienzle@users.sf.net> | |
125 ## Created: 10 October 2001 (CVS) | |
126 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
127 | |
128 function retval = datestr (date, f, p) | |
129 | |
130 persistent dateform names_mmmm names_mmm names_m names_dddd names_ddd names_d; | |
131 | |
132 if (isempty (dateform)) | |
133 | |
134 dateform = cell (32, 1); | |
135 dateform{1} = "dd-mmm-yyyy HH:MM:SS"; | |
136 dateform{2} = "dd-mmm-yyyy"; | |
137 dateform{3} = "mm/dd/yy"; | |
138 dateform{4} = "mmm"; | |
139 dateform{5} = "m"; | |
140 dateform{6} = "mm"; | |
141 dateform{7} = "mm/dd"; | |
142 dateform{8} = "dd"; | |
143 dateform{9} = "ddd"; | |
144 dateform{10} = "d"; | |
145 dateform{11} = "yyyy"; | |
146 dateform{12} = "yy"; | |
147 dateform{13} = "mmmyy"; | |
148 dateform{14} = "HH:MM:SS"; | |
149 dateform{15} = "HH:MM:SS PM"; | |
150 dateform{16} = "HH:MM"; | |
151 dateform{17} = "HH:MM PM"; | |
152 dateform{18} = "QQ-YY"; | |
153 dateform{19} = "QQ"; | |
154 dateform{20} = "dd/mm"; | |
155 dateform{21} = "dd/mm/yy"; | |
156 dateform{22} = "mmm.dd.yyyy HH:MM:SS"; | |
157 dateform{23} = "mmm.dd.yyyy"; | |
158 dateform{24} = "mm/dd/yyyy"; | |
159 dateform{25} = "dd/mm/yyyy"; | |
160 dateform{26} = "yy/mm/dd"; | |
161 dateform{27} = "yyyy/mm/dd"; | |
162 dateform{28} = "QQ-YYYY"; | |
163 dateform{29} = "mmmyyyy"; | |
164 dateform{30} = "yyyymmdd"; | |
165 dateform{31} = "yyyymmddTHHMMSS"; | |
166 dateform{32} = "yyyy-mm-dd HH:MM:SS"; | |
167 | |
168 names_m = {"J"; "F"; "M"; "A"; "M"; "J"; "J"; "A"; "S"; "O"; "N"; "D"}; | |
169 | |
170 names_d = {"S"; "M"; "T"; "W"; "T"; "F"; "S"}; | |
171 | |
172 endif | |
173 | |
174 if (nargin < 1 || nargin > 3) | |
6046 | 175 print_usage (); |
5687 | 176 endif |
177 | |
178 if (nargin < 2) | |
179 f = []; | |
180 endif | |
181 if (nargin < 3) | |
182 p = []; | |
183 endif | |
184 | |
185 if (ischar (date)) | |
186 t = date; | |
187 date = cell (1); | |
188 date{1} = t; | |
189 endif | |
190 | |
8506 | 191 ## Guess, so we might be wrong. |
5687 | 192 if (iscell (date) || columns (date) != 6) |
193 v = datevec (date, p); | |
194 else | |
7492 | 195 v = []; |
7493 | 196 if (columns (date) == 6) |
197 ## Make sure that the input really is a datevec. | |
198 maxdatevec = [Inf, 12, 31, 23, 59, 60]; | |
7492 | 199 for i = 1:numel (maxdatevec) |
8112
31e86163b752
Add the datetick function
David Bateman <dbateman@free.fr>
parents:
8098
diff
changeset
|
200 if (any (date(:,i) > maxdatevec(i)) || |
31e86163b752
Add the datetick function
David Bateman <dbateman@free.fr>
parents:
8098
diff
changeset
|
201 (i != 6 && any (floor (date(:, i)) != date (:, i)))) |
7492 | 202 v = datevec (date, p); |
203 break; | |
204 endif | |
205 endfor | |
206 endif | |
7493 | 207 if (isempty (v)) |
7492 | 208 v = date; |
209 endif | |
5687 | 210 endif |
211 | |
212 for i = 1:(rows (v)) | |
213 | |
214 if (isempty (f) || f == -1) | |
215 if (v(i,4:6) == 0) | |
216 f = 1; | |
8506 | 217 ## elseif (v(i,1:3) == [0, 1, 1]) |
5687 | 218 elseif (v(i,1:3) == [-1, 12, 31]) |
219 f = 16; | |
220 else | |
221 f = 0; | |
222 endif | |
223 endif | |
224 | |
225 if (isnumeric (f)) | |
226 df = dateform{f + 1}; | |
227 else | |
228 df = f; | |
229 endif | |
230 | |
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
|
231 df_orig = df; |
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 df = regexprep (df, "[AP]M", "%p"); |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
233 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
|
234 ## 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
|
235 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
|
236 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
|
237 df = strrep (df, "HH", sprintf ("%2d", v(i,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
|
238 endif |
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 |
8643
92e193030b77
bugfix in datestr with YYYY and dd
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8506
diff
changeset
|
240 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
|
241 |
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 = regexprep (df, "[Yy][Yy]", "%y"); |
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 = regexprep (df, "[Dd][Dd][Dd][Dd]", "%A"); |
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 df = regexprep (df, "[Dd][Dd][Dd]", "%a"); |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
247 |
8643
92e193030b77
bugfix in datestr with YYYY and dd
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8506
diff
changeset
|
248 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
|
249 |
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 tmp = names_d{weekday (datenum (v(i,1), v(i,2), v(i,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
|
251 df = regexprep (df, "([^%])[Dd]", sprintf ("$1%s", tmp)); |
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 df = regexprep (df, "^[Dd]", sprintf ("%s", tmp)); |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
253 |
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 df = strrep (df, "mmmm", "%B"); |
5687 | 255 |
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
|
256 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
|
257 |
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 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
|
259 |
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 tmp = names_m{v(i,2)}; |
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 pos = regexp (df, "[^%]m") + 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 df(pos) = tmp; |
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 df = regexprep (df, "^m", tmp); |
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 |
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 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
|
266 |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
267 df = strrep (df, "SS", "%S"); |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
268 |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
269 df = regexprep (df, "[Qq][Qq]", sprintf ("Q%d", fix ((v(i,2) + 2) / 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
|
270 |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 tm.sec = fix (sec); |
229bd50e6e8f
datestr.m: convert format and use strtftime for most of the actual conversion
John W. Eaton <jwe@octave.org>
parents:
7969
diff
changeset
|
279 tm.usec = fix (rem (sec, 1) * 1e6); |
9574
19124db6fc1c
datestr: set tm.isdst to -1 before calling mktime
E. Joshua Rigler <relgire@gmail.com>
parents:
9079
diff
changeset
|
280 ## Force mktime to check for DST. |
9586
1393896df3b3
datestr: add missing semicolon
John W. Eaton <jwe@octave.org>
parents:
9574
diff
changeset
|
281 tm.isdst = -1; |
9574
19124db6fc1c
datestr: set tm.isdst to -1 before calling mktime
E. Joshua Rigler <relgire@gmail.com>
parents:
9079
diff
changeset
|
282 |
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
|
283 str = strftime (df, localtime (mktime (tm))); |
5687 | 284 |
285 if (i == 1) | |
286 retval = str; | |
287 else | |
288 retval = [retval; str]; | |
289 endif | |
290 | |
291 endfor | |
292 | |
293 endfunction | |
294 | |
295 # simple tests | |
296 %!shared testtime | |
297 %! testtime = [2005.0000, 12.0000, 18.0000, 2.0000, 33.0000, 17.3822]; | |
298 %!assert(datestr(testtime,0),"18-Dec-2005 02:33:17"); | |
299 %!assert(datestr(testtime,1),"18-Dec-2005"); | |
300 %!assert(datestr(testtime,2),"12/18/05"); | |
301 %!assert(datestr(testtime,3),"Dec"); | |
302 %!assert(datestr(testtime,4),"D"); | |
303 %!assert(datestr(testtime,5),"12"); | |
304 %!assert(datestr(testtime,6),"12/18"); | |
305 %!assert(datestr(testtime,7),"18"); | |
306 %!assert(datestr(testtime,8),"Sun"); | |
307 %!assert(datestr(testtime,9),"S"); | |
308 %!assert(datestr(testtime,10),"2005"); | |
309 %!assert(datestr(testtime,11),"05"); | |
310 %!assert(datestr(testtime,12),"Dec05"); | |
311 %!assert(datestr(testtime,13),"02:33:17"); | |
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
|
312 %!assert(datestr(testtime,14)," 2:33:17 AM"); |
5687 | 313 %!assert(datestr(testtime,15),"02:33"); |
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
|
314 %!assert(datestr(testtime,16)," 2:33 AM"); |
5687 | 315 %!assert(datestr(testtime,17),"Q4-05"); |
316 %!assert(datestr(testtime,18),"Q4"); | |
317 %!assert(datestr(testtime,19),"18/12"); | |
318 %!assert(datestr(testtime,20),"18/12/05"); | |
319 %!assert(datestr(testtime,21),"Dec.18.2005 02:33:17"); | |
320 %!assert(datestr(testtime,22),"Dec.18.2005"); | |
321 %!assert(datestr(testtime,23),"12/18/2005"); | |
322 %!assert(datestr(testtime,24),"18/12/2005"); | |
323 %!assert(datestr(testtime,25),"05/12/18"); | |
324 %!assert(datestr(testtime,26),"2005/12/18"); | |
325 %!assert(datestr(testtime,27),"Q4-2005"); | |
326 %!assert(datestr(testtime,28),"Dec2005"); | |
327 %!assert(datestr(testtime,29),"20051218"); | |
328 %!assert(datestr(testtime,30),"20051218T023317"); | |
329 %!assert(datestr(testtime,31),"2005-12-18 02:33:17"); | |
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
|
330 %!assert(datestr(testtime+[0 0 3 0 0 0],"dddd"),"Wednesday") |
7492 | 331 ## avoid the bug where someone happens to give a vector of datenums that |
332 ## happens to be 6 wide | |
333 %!assert(datestr(733452.933:733457.933), ["14-Feb-2008 22:23:31";"15-Feb-2008 22:23:31";"16-Feb-2008 22:23:31";"17-Feb-2008 22:23:31";"18-Feb-2008 22:23:31";"19-Feb-2008 22:23:31"]) | |
5687 | 334 # demos |
335 %!demo | |
336 %! datestr (now ()) | |
337 %!demo | |
338 %! datestr (rem (now (), 1)) | |
339 %!demo | |
340 %! datestr (floor (now ())) |