Mercurial > octave
annotate scripts/time/datestr.m @ 27918:b442ec6dda5c
use centralized file for copyright info for individual contributors
* COPYRIGHT.md: New file.
* In most other files, use "Copyright (C) YYYY-YYYY The Octave Project
Developers" instead of tracking individual names in separate source
files. The motivation is to reduce the effort required to update the
notices each year.
Until now, the Octave source files contained copyright notices that
list individual contributors. I adopted these file-scope copyright
notices because that is what everyone was doing 30 years ago in the
days before distributed version control systems. But now, with many
contributors and modern version control systems, having these
file-scope copyright notices causes trouble when we update copyright
years or refactor code.
Over time, the file-scope copyright notices may become outdated as new
contributions are made or code is moved from one file to
another. Sometimes people contribute significant patches but do not
add a line claiming copyright. Other times, people add a copyright
notice for their contribution but then a later refactoring moves part
or all of their contribution to another file and the notice is not
moved with the code. As a practical matter, moving such notices is
difficult -- determining what parts are due to a particular
contributor requires a time-consuming search through the project
history. Even managing the yearly update of copyright years is
problematic. We have some contributors who are no longer
living. Should we update the copyright dates for their contributions
when we release new versions? Probably not, but we do still want to
claim copyright for the project as a whole.
To minimize the difficulty of maintaining the copyright notices, I
would like to change Octave's sources to use what is described here:
https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
in the section "Maintaining centralized copyright notices":
The centralized notice approach consolidates all copyright
notices in a single location, usually a top-level file.
This file should contain all of the copyright notices
provided project contributors, unless the contribution was
clearly insignificant. It may also credit -- without a copyright
notice -- anyone who helped with the project but did not
contribute code or other copyrighted material.
This approach captures less information about contributions
within individual files, recognizing that the DVCS is better
equipped to record those details. As we mentioned before, it
does have one disadvantage as compared to the file-scope
approach: if a single file is separated from the distribution,
the recipient won't see the contributors' copyright notices.
But this can be easily remedied by including a single
copyright notice in each file's header, pointing to the
top-level file:
Copyright YYYY-YYYY The Octave Project Developers
See the COPYRIGHT file at the top-level directory
of this distribution or at https://octave.org/COPYRIGHT.html.
followed by the usual GPL copyright statement.
For more background, see the discussion here:
https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html
Most files in the following directories have been skipped intentinally
in this changeset:
doc
libgui/qterminal
liboctave/external
m4
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 15:38:17 -0500 |
parents | 00f796120a6d |
children | 1891570abac8 |
rev | line source |
---|---|
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
1 ## Copyright (C) 2000-2019 The Octave Project Developers |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 ## |
5687 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
5687 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
12 ## (at your option) any later version. |
5687 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
17 ## GNU General Public License for more details. |
5687 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
5687 | 22 |
23 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
24 ## @deftypefn {} {@var{str} =} datestr (@var{date}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
25 ## @deftypefnx {} {@var{str} =} datestr (@var{date}, @var{f}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20162
diff
changeset
|
26 ## @deftypefnx {} {@var{str} =} datestr (@var{date}, @var{f}, @var{p}) |
25472
9771111f04f4
doc: Use @var rather than @code to mark inputs to functions in docstrings.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
27 ## Format the given date/time according to the format @var{f} and return |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
28 ## the result in @var{str}. |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
29 ## |
26106
5b527588b489
datestr.m: Clarify behavior if input date is a string.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25472
diff
changeset
|
30 ## @var{date} is a serial date number (see @code{datenum}), a date vector (see |
26293
095eb3a04f43
doc: grammarcheck m-file scripts ahead of 5.0 release.
Rik <rik@octave.org>
parents:
26106
diff
changeset
|
31 ## @code{datevec}), or a string or cell array of strings. In the latter case, |
26106
5b527588b489
datestr.m: Clarify behavior if input date is a string.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25472
diff
changeset
|
32 ## it is passed to @code{datevec} to guess the input date format. |
5687 | 33 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
34 ## @var{f} can be an integer which corresponds to one of the codes in the table |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
35 ## below, or a date format string. |
5687 | 36 ## |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
37 ## @var{p} is the year at the start of the century in which two-digit years are |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
38 ## to be interpreted in. If not specified, it defaults to the current year |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
39 ## minus 50. |
5687 | 40 ## |
41 ## For example, the date 730736.65149 (2000-09-07 15:38:09.0934) would be | |
42 ## formatted as follows: | |
43 ## | |
44 ## @multitable @columnfractions 0.1 0.45 0.35 | |
45 ## @headitem Code @tab Format @tab Example | |
19418
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
46 ## @item 0 @tab dd-mmm-yyyy HH:MM:SS @tab 07-Sep-2000 15:38:09 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
47 ## @item 1 @tab dd-mmm-yyyy @tab 07-Sep-2000 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
48 ## @item 2 @tab mm/dd/yy @tab 09/07/00 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
49 ## @item 3 @tab mmm @tab Sep |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
50 ## @item 4 @tab m @tab S |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
51 ## @item 5 @tab mm @tab 09 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
52 ## @item 6 @tab mm/dd @tab 09/07 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
53 ## @item 7 @tab dd @tab 07 |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
54 ## @item 8 @tab ddd @tab Thu |
06931d787450
doc: Align columns in @multitable in datestr.m docstring.
Rik <rik@octave.org>
parents:
19414
diff
changeset
|
55 ## @item 9 @tab d @tab T |
5687 | 56 ## @item 10 @tab yyyy @tab 2000 |
57 ## @item 11 @tab yy @tab 00 | |
58 ## @item 12 @tab mmmyy @tab Sep00 | |
59 ## @item 13 @tab HH:MM:SS @tab 15:38:09 | |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
60 ## @item 14 @tab HH:MM:SS PM @tab 3:38:09 PM |
5687 | 61 ## @item 15 @tab HH:MM @tab 15:38 |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
62 ## @item 16 @tab HH:MM PM @tab 3:38 PM |
5687 | 63 ## @item 17 @tab QQ-YY @tab Q3-00 |
64 ## @item 18 @tab QQ @tab Q3 | |
14723
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
65 ## @item 19 @tab dd/mm @tab 07/09 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
66 ## @item 20 @tab dd/mm/yy @tab 07/09/00 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
67 ## @item 21 @tab mmm.dd,yyyy HH:MM:SS @tab Sep.07,2000 15:38:08 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
68 ## @item 22 @tab mmm.dd,yyyy @tab Sep.07,2000 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
69 ## @item 23 @tab mm/dd/yyyy @tab 09/07/2000 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
70 ## @item 24 @tab dd/mm/yyyy @tab 07/09/2000 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
71 ## @item 25 @tab yy/mm/dd @tab 00/09/07 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
72 ## @item 26 @tab yyyy/mm/dd @tab 2000/09/07 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
73 ## @item 27 @tab QQ-YYYY @tab Q3-2000 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
74 ## @item 28 @tab mmmyyyy @tab Sep2000 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
75 ## @item 29 @tab yyyy-mm-dd @tab 2000-09-07 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
76 ## @item 30 @tab yyyymmddTHHMMSS @tab 20000907T153808 |
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
77 ## @item 31 @tab yyyy-mm-dd HH:MM:SS @tab 2000-09-07 15:38:08 |
5687 | 78 ## @end multitable |
79 ## | |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
80 ## If @var{f} is a format string, the following symbols are recognized: |
5687 | 81 ## |
82 ## @multitable @columnfractions 0.1 0.7 0.2 | |
83 ## @headitem Symbol @tab Meaning @tab Example | |
84 ## @item yyyy @tab Full year @tab 2005 | |
14723
3fd6f637c573
doc: Correct errors and improve docstring for datestr.m
Rik <octave@nomad.inbox5.com>
parents:
14237
diff
changeset
|
85 ## @item yy @tab Two-digit year @tab 05 |
5687 | 86 ## @item mmmm @tab Full month name @tab December |
87 ## @item mmm @tab Abbreviated month name @tab Dec | |
88 ## @item mm @tab Numeric month number (padded with zeros) @tab 01, 08, 12 | |
89 ## @item m @tab First letter of month name (capitalized) @tab D | |
90 ## @item dddd @tab Full weekday name @tab Sunday | |
91 ## @item ddd @tab Abbreviated weekday name @tab Sun | |
92 ## @item dd @tab Numeric day of month (padded with zeros) @tab 11 | |
93 ## @item d @tab First letter of weekday name (capitalized) @tab S | |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
94 ## @item HH @tab Hour of day, padded with zeros, @tab 09:00 |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
95 ## @item @tab or padded with spaces if PM is set @tab 9:00 AM |
5687 | 96 ## @item MM @tab Minute of hour (padded with zeros) @tab 10:05 |
97 ## @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
|
98 ## @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
|
99 ## @item AM @tab Use 12-hour time format @tab 11:30 AM |
5687 | 100 ## @item PM @tab Use 12-hour time format @tab 11:30 PM |
101 ## @end multitable | |
102 ## | |
20162
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
103 ## If @var{f} is not specified or is @code{-1}, then use 0, 1 or 16, depending |
2645f9ef8c88
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19865
diff
changeset
|
104 ## on whether the date portion or the time portion of @var{date} is empty. |
5687 | 105 ## |
106 ## If @var{p} is nor specified, it defaults to the current year minus 50. | |
107 ## | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
108 ## 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
|
109 ## is returned. |
5687 | 110 ## |
13856
d490ca8ab1a5
Modernize function implementations and docstrings in scripts/time.
Rik <octave@nomad.inbox5.com>
parents:
13848
diff
changeset
|
111 ## @seealso{datenum, datevec, date, now, clock} |
5687 | 112 ## @end deftypefn |
113 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
114 ## FIXME: parse arbitrary code strings. |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
115 ## e.g., for Wednesday 2001-03-05 09:04:06 AM, use |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
116 ## yy 01 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
117 ## yyyy 2001 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
118 ## m M |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
119 ## mm 03 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
120 ## mmm Mar |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
121 ## d W |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
122 ## dd 05 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
123 ## ddd Wed |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
124 ## HH 09 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
125 ## MM 04 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
126 ## SS 06 |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
127 ## PM AM |
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
8112
diff
changeset
|
128 ## 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
|
129 ## 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
|
130 ## concatenate. |
5687 | 131 |
132 ## Author: pkienzle <pkienzle@users.sf.net> | |
133 ## Created: 10 October 2001 (CVS) | |
134 ## Adapted-By: William Poetra Yoga Hadisoeseno <williampoetra@gmail.com> | |
135 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
136 function retval = datestr (date, f = [], p = []) |
5687 | 137 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
138 persistent dateform names_mmmm names_m names_d; |
5687 | 139 |
140 if (isempty (dateform)) | |
141 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
|
142 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
|
143 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
|
144 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
|
145 dateform{4} = "mmm"; |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
146 dateform{5} = "m"; |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
147 dateform{6} = "mm"; |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
148 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
|
149 dateform{8} = "dd"; |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
150 dateform{9} = "ddd"; |
5687 | 151 dateform{10} = "d"; |
152 dateform{11} = "yyyy"; | |
153 dateform{12} = "yy"; | |
154 dateform{13} = "mmmyy"; | |
155 dateform{14} = "HH:MM:SS"; | |
156 dateform{15} = "HH:MM:SS PM"; | |
157 dateform{16} = "HH:MM"; | |
158 dateform{17} = "HH:MM PM"; | |
159 dateform{18} = "QQ-YY"; | |
160 dateform{19} = "QQ"; | |
161 dateform{20} = "dd/mm"; | |
162 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
|
163 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
|
164 dateform{23} = "mmm.dd,yyyy"; |
5687 | 165 dateform{24} = "mm/dd/yyyy"; |
166 dateform{25} = "dd/mm/yyyy"; | |
167 dateform{26} = "yy/mm/dd"; | |
168 dateform{27} = "yyyy/mm/dd"; | |
169 dateform{28} = "QQ-YYYY"; | |
170 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
|
171 dateform{30} = "yyyy-mm-dd"; |
5687 | 172 dateform{31} = "yyyymmddTHHMMSS"; |
173 dateform{32} = "yyyy-mm-dd HH:MM:SS"; | |
174 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
175 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
|
176 names_d = {"S", "M", "T", "W", "T", "F", "S"}; |
5687 | 177 endif |
178 | |
179 if (nargin < 1 || nargin > 3) | |
6046 | 180 print_usage (); |
5687 | 181 endif |
182 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
183 ## 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
|
184 if (ischar (date) || iscellstr (date) || columns (date) != 6) |
5687 | 185 v = datevec (date, p); |
186 else | |
7492 | 187 v = []; |
7493 | 188 if (columns (date) == 6) |
189 ## Make sure that the input really is a datevec. | |
190 maxdatevec = [Inf, 12, 31, 23, 59, 60]; | |
19865
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
191 if (any (max (date, 1) > maxdatevec) |
e9f89866074c
maint: Cleanup some .m files to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
192 || any (date(:,1:5) != floor (date(:,1:5)))) |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
193 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
|
194 endif |
7492 | 195 endif |
7493 | 196 if (isempty (v)) |
7492 | 197 v = date; |
198 endif | |
5687 | 199 endif |
200 | |
23339
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
201 ## Round fractional seconds >= 0.9995 s to next full second. |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
202 idx = v(:,6) - fix (v(:,6)) >= 0.9995; |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
203 if (any (idx)) |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
204 v(idx,6) = fix (v(idx,6)) + 1; |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
205 v(idx,:) = datevec (datenum (v(idx,:))); |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
206 endif |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
207 |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
208 ## Automatic format selection |
23303
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
209 if (isempty (f)) |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
210 if (v(:,4:6) == 0) |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
211 f = 1; |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
212 elseif (v(:,1:3) == [-1, 12, 31]) |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
213 f = 16; |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
214 else |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
215 f = 0; |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
216 endif |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
217 endif |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
218 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
219 retval = ""; |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
220 for i = 1 : rows (v) |
5687 | 221 |
222 if (isnumeric (f)) | |
223 df = dateform{f + 1}; | |
224 else | |
225 df = f; | |
226 endif | |
227 | |
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 df_orig = df; |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
229 df = strrep (df, "AM", "%p"); |
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
230 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
|
231 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
|
232 ## 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
|
233 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
|
234 else |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
235 hr = mod (v(i,4), 12); |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
236 if (hr == 0) |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
237 hr = 12; |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
238 endif |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
239 df = strrep (df, "HH", sprintf ("%2d", hr)); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
240 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
|
241 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
242 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
|
243 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
244 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
|
245 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
246 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
|
247 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
248 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
|
249 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
250 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
|
251 |
11328
f286a874617c
datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
252 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
|
253 tmp = names_d{wday}; |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
254 df = regexprep (df, "([^%])[Dd]", sprintf ("$1%s", tmp)); |
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
255 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
|
256 |
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 df = strrep (df, "mmmm", "%B"); |
5687 | 258 |
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
|
259 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
|
260 |
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 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
|
262 |
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 tmp = names_m{v(i,2)}; |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
264 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
|
265 df(pos) = tmp; |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
266 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
|
267 |
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 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
|
269 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
270 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
|
271 |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17839
diff
changeset
|
272 df = strrep (df, "FFF", sprintf ("%03d", |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17839
diff
changeset
|
273 round (1000 * (v(i,6) - fix (v(i,6)))))); |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
274 |
19414
a2a79462b7b8
datestr.m: Clean up use of []/"" and single/double quotes (bug #43841).
Rik <rik@octave.org>
parents:
18857
diff
changeset
|
275 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
|
276 |
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 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 tm.wday = wday - 1; |
18857
7bbe3658c5ef
maint: Use "FIXME:" coding convention in m-files.
Rik <rik@octave.org>
parents:
18650
diff
changeset
|
287 ## FIXME: Do we need YDAY and DST? How should they be computed? |
11328
f286a874617c
datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
288 ## 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
|
289 ## 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
|
290 ## tm.yday = ?; |
f286a874617c
datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
291 ## tm.isdst = ?; |
f286a874617c
datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
292 |
f286a874617c
datestr: handle dates before 1970-01-01
John W. Eaton <jwe@octave.org>
parents:
11149
diff
changeset
|
293 str = strftime (df, tm); |
5687 | 294 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
295 retval = [retval; str]; |
5687 | 296 |
297 endfor | |
298 | |
299 endfunction | |
300 | |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
301 |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
302 %!demo |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
303 %! ## 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
|
304 %! 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
|
305 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
306 %!demo |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
307 %! ## 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
|
308 %! 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
|
309 |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
310 %!demo |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
311 %! ## 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
|
312 %! 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
|
313 |
5687 | 314 %!shared testtime |
315 %! 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
|
316 %!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
|
317 %!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
|
318 %!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
|
319 %!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
|
320 %!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
|
321 %!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
|
322 %!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
|
323 %!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
|
324 %!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
|
325 %!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
|
326 %!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
|
327 %!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
|
328 %!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
|
329 %!assert (datestr (testtime,13), "02:33:17") |
17839
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
330 ## Mac OS X interprets %p parameter to strftime as lower case am/pm indicator. |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
331 ## Accommodate this, although no other UNIX-based OS does this. |
17839
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
332 %!test |
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
333 %! obs = toupper (datestr (testtime,14)); |
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
334 %! assert (obs, " 2:33:17 AM"); |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
335 %!assert (datestr (testtime,15), "02:33") |
17839
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
336 %!test |
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
337 %! obs = toupper (datestr (testtime,16)); |
2ff47214de72
datestr.m: Accomodate Mac OS X odd support of %p in strftime.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
338 %! assert (obs, " 2:33 AM"); |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
339 %!test <*48071> |
21793
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
340 %! testtime2 = testtime; |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
341 %! testtime2(4) = 15; |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
342 %! obs = toupper (datestr (testtime2,16)); |
50f49dcae277
datestr.m: Fix Matlab incompatibility for format #16 (bug #48071).
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
343 %! assert (obs, " 3:33 PM"); |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
344 %!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
|
345 %!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
|
346 %!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
|
347 %!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
|
348 %!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
|
349 %!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
|
350 %!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
|
351 %!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
|
352 %!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
|
353 %!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
|
354 %!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
|
355 %!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
|
356 %!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
|
357 %!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
|
358 %!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
|
359 %!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
|
360 ## 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
|
361 %!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
|
362 ## 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
|
363 %!assert (datestr (testtime, "HH:MM:SS:FFF"), "02:33:17:382") |
23303
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
364 ## Test automatic format detection over vectors |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
365 %!assert (datestr ([2017 03 16 0 0 0; 2017 03 16 0 0 1]), |
4aa13310250c
datestr.m: Do automatic format detection across all entries in vector (bug #50558).
Lars Kindermann
parents:
23220
diff
changeset
|
366 %! char ("16-Mar-2017 00:00:00", "16-Mar-2017 00:00:01")) |
23339
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
367 ## Test for correct millisecond rounding |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
368 %!assert (datestr (datenum ("1:00") - datenum ("0:55"), "HH:MM:SS.FFF"), |
68dbde0e670a
datestr.m: Correct rounding to milliseconds (bug #50673).
larskindermann
parents:
23303
diff
changeset
|
369 %! "00:05:00.000") |
11329
6b073da9d7fc
ChangeLog fix and new datestr test omitted from previous change
John W. Eaton <jwe@octave.org>
parents:
11328
diff
changeset
|
370 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
371 ## Test input validation |
13848
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
372 %!error datestr () |
40e32fe44aaa
Ugrade time functions to accept millisecond format string FFF (Bug #34586)
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
373 %!error datestr (1, 2, 3, 4) |