Mercurial > octave
annotate libinterp/corefcn/time.cc @ 20719:d903cccb8de8
doc: Periodic spellcheck of documentation.
* aspell-octave.en.pws: Add new spelling exceptions to private dictionary.
* diffeq.txi, plot.txi, time.cc, validateattributes.m, imwrite.m, ode45.m:
Add nospell macro around unusual words.
* uicontextmenu.m, uipanel.m, uipushtool.m, uitoggletool.m, uitoolbar.m:
Correct "propertes" to "properties".
* uicontrol.m: Correct "propertes" to "properties". Correct "slelection" to
"selection".
* cor_test.m: Correct "produt" to "product".
author | Rik <rik@octave.org> |
---|---|
date | Wed, 18 Nov 2015 22:07:12 -0800 |
parents | 571508c1ed06 |
children | fb128aafc322 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19403
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2928 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2928 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2928 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <string> | |
28 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
29 #include "defun.h" |
2928 | 30 #include "error.h" |
31 #include "oct-map.h" | |
3254 | 32 #include "oct-time.h" |
2928 | 33 #include "ov.h" |
34 #include "oct-obj.h" | |
35 | |
36 // Date and time functions. | |
37 | |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
38 static octave_scalar_map |
3254 | 39 mk_tm_map (const octave_base_tm& t) |
2928 | 40 { |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
41 octave_scalar_map m; |
2928 | 42 |
4675 | 43 m.assign ("usec", static_cast<double> (t.usec ())); |
44 m.assign ("sec", static_cast<double> (t.sec ())); | |
45 m.assign ("min", static_cast<double> (t.min ())); | |
46 m.assign ("hour", static_cast<double> (t.hour ())); | |
47 m.assign ("mday", static_cast<double> (t.mday ())); | |
48 m.assign ("mon", static_cast<double> (t.mon ())); | |
49 m.assign ("year", static_cast<double> (t.year ())); | |
50 m.assign ("wday", static_cast<double> (t.wday ())); | |
51 m.assign ("yday", static_cast<double> (t.yday ())); | |
52 m.assign ("isdst", static_cast<double> (t.isdst ())); | |
20375
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
53 m.assign ("gmtoff", static_cast<double> (t.gmtoff ())); |
4675 | 54 m.assign ("zone", t.zone ()); |
2928 | 55 |
56 return m; | |
57 } | |
58 | |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
59 static inline int |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
60 intfield (const octave_scalar_map& m, const std::string& k, const char *who) |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
61 { |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
62 int retval = 0; |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
63 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
64 octave_value v = m.getfield (k); |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
65 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
66 if (! v.is_empty ()) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
67 retval = v.xint_value ("%s: invalid TM_STRUCT argument", who); |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
68 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
69 return retval; |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
70 } |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
71 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
72 static inline std::string |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
73 stringfield (const octave_scalar_map& m, const std::string& k, const char *who) |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
74 { |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
75 std::string retval; |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
76 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
77 octave_value v = m.getfield (k); |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
78 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
79 if (! v.is_empty ()) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
80 retval = v.xstring_value ("%s: invalid TM_STRUCT argument", who); |
11042
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
81 |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
82 return retval; |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
83 } |
f6b7b6e5b8b8
time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11005
diff
changeset
|
84 |
3254 | 85 static octave_base_tm |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
86 extract_tm (const octave_scalar_map& m, const char *who) |
2928 | 87 { |
3254 | 88 octave_base_tm tm; |
2928 | 89 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
90 tm.usec (intfield (m, "usec", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
91 tm.sec (intfield (m, "sec", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
92 tm.min (intfield (m, "min", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
93 tm.hour (intfield (m, "hour", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
94 tm.mday (intfield (m, "mday", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
95 tm.mon (intfield (m, "mon", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
96 tm.year (intfield (m, "year", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
97 tm.wday (intfield (m, "wday", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
98 tm.yday (intfield (m, "yday", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
99 tm.isdst (intfield (m, "isdst", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
100 tm.gmtoff (intfield (m, "gmtoff", who)); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
101 tm.zone (stringfield (m, "zone", who)); |
2928 | 102 |
3254 | 103 return tm; |
2928 | 104 } |
105 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
106 DEFUN (time, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
107 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
108 @deftypefn {Built-in Function} {@var{seconds} =} time ()\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
109 Return the current time as the number of seconds since the epoch.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
110 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
111 The epoch is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
112 1970. For example, on Monday February 17, 1997 at 07:15:06 CUT, the value\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
113 returned by @code{time} was 856163706.\n\ |
5688 | 114 @seealso{strftime, strptime, localtime, gmtime, mktime, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
3301 | 115 @end deftypefn") |
2928 | 116 { |
3255 | 117 octave_value retval; |
2928 | 118 |
3255 | 119 if (args.length () == 0) |
7065 | 120 retval = octave_time (); |
3255 | 121 else |
5823 | 122 print_usage (); |
3255 | 123 |
124 return retval; | |
2928 | 125 } |
126 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
127 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
128 %!assert (time () > 0) |
19142
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
129 |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
130 %!error time (1) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
131 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
132 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
133 DEFUN (gmtime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
134 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
135 @deftypefn {Built-in Function} {@var{tm_struct} =} gmtime (@var{t})\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
136 Given a value returned from @code{time}, or any non-negative integer,\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11553
diff
changeset
|
137 return a time structure corresponding to CUT (Coordinated Universal Time).\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
138 \n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
139 For example:\n\ |
2928 | 140 \n\ |
3301 | 141 @example\n\ |
142 @group\n\ | |
143 gmtime (time ())\n\ | |
144 @result{} @{\n\ | |
145 usec = 0\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
146 sec = 6\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
147 min = 15\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
148 hour = 7\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
149 mday = 17\n\ |
3301 | 150 mon = 1\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
151 year = 97\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
152 wday = 1\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
153 yday = 47\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
154 isdst = 0\n\ |
20375
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
155 gmtoff = 0\n\ |
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
156 zone = GMT\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
157 @}\n\ |
3301 | 158 @end group\n\ |
159 @end example\n\ | |
5688 | 160 @seealso{strftime, strptime, localtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
3301 | 161 @end deftypefn") |
2928 | 162 { |
3465 | 163 octave_value retval; |
2928 | 164 |
165 if (args.length () == 1) | |
166 { | |
167 double tmp = args(0).double_value (); | |
168 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20375
diff
changeset
|
169 retval = octave_value (mk_tm_map (octave_gmtime (tmp))); |
2928 | 170 } |
171 else | |
5823 | 172 print_usage (); |
2928 | 173 |
174 return retval; | |
175 } | |
176 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
177 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
178 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
179 %! ts = gmtime (time ()); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
180 %! assert (isstruct (ts)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
181 %! assert (isfield (ts, "usec")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
182 %! assert (isfield (ts, "year")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
183 %! assert (isfield (ts, "mon")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
184 %! assert (isfield (ts, "mday")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
185 %! assert (isfield (ts, "sec")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
186 %! assert (isfield (ts, "min")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
187 %! assert (isfield (ts, "wday")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
188 %! assert (isfield (ts, "hour")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
189 %! assert (isfield (ts, "isdst")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
190 %! assert (isfield (ts, "yday")); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
191 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
192 %!error gmtime () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
193 %!error gmtime (1, 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
194 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
195 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
196 DEFUN (localtime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
198 @deftypefn {Built-in Function} {@var{tm_struct} =} localtime (@var{t})\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
199 Given a value returned from @code{time}, or any non-negative integer,\n\ |
3301 | 200 return a time structure corresponding to the local time zone.\n\ |
2928 | 201 \n\ |
3301 | 202 @example\n\ |
203 @group\n\ | |
204 localtime (time ())\n\ | |
205 @result{} @{\n\ | |
206 usec = 0\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
207 sec = 6\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
208 min = 15\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
209 hour = 1\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
210 mday = 17\n\ |
3301 | 211 mon = 1\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
212 year = 97\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
213 wday = 1\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
214 yday = 47\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
215 isdst = 0\n\ |
20375
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
216 gmtoff = -21600\n\ |
3301 | 217 zone = CST\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
218 @}\n\ |
3301 | 219 @end group\n\ |
220 @end example\n\ | |
5688 | 221 @seealso{strftime, strptime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
3301 | 222 @end deftypefn") |
2928 | 223 { |
3465 | 224 octave_value retval; |
2928 | 225 |
226 if (args.length () == 1) | |
227 { | |
228 double tmp = args(0).double_value (); | |
229 | |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20375
diff
changeset
|
230 retval = octave_value (mk_tm_map (octave_localtime (tmp))); |
2928 | 231 } |
232 else | |
5823 | 233 print_usage (); |
2928 | 234 |
235 return retval; | |
236 } | |
237 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
238 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
239 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
240 %! ts = localtime (time ()); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
241 %! assert (isstruct (ts)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
242 %! assert (isfield (ts, "usec")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
243 %! assert (isfield (ts, "year")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
244 %! assert (isfield (ts, "mon")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
245 %! assert (isfield (ts, "mday")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
246 %! assert (isfield (ts, "sec")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
247 %! assert (isfield (ts, "min")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
248 %! assert (isfield (ts, "wday")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
249 %! assert (isfield (ts, "hour")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
250 %! assert (isfield (ts, "isdst")); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
251 %! assert (isfield (ts, "yday")); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
252 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
253 %!error localtime () |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
254 %!error localtime (1, 2) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
255 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
256 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
257 DEFUN (mktime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
258 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
259 @deftypefn {Built-in Function} {@var{seconds} =} mktime (@var{tm_struct})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
260 Convert a time structure corresponding to the local time to the number of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
261 seconds since the epoch.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
262 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
263 For example:\n\ |
3301 | 264 \n\ |
265 @example\n\ | |
266 @group\n\ | |
7097 | 267 mktime (localtime (time ()))\n\ |
3301 | 268 @result{} 856163706\n\ |
269 @end group\n\ | |
270 @end example\n\ | |
5688 | 271 @seealso{strftime, strptime, localtime, gmtime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
3301 | 272 @end deftypefn") |
2928 | 273 { |
3465 | 274 octave_value retval; |
2928 | 275 |
3254 | 276 if (args.length () == 1) |
2928 | 277 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
278 octave_scalar_map map = args(0).xscalar_map_value ("mktime: TM_STRUCT argument must be a structure"); |
3254 | 279 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
280 octave_base_tm tm = extract_tm (map, "mktime"); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
281 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
282 retval = octave_time (tm); |
2928 | 283 } |
284 else | |
5823 | 285 print_usage (); |
2928 | 286 |
287 return retval; | |
288 } | |
289 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
290 /* |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
291 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
292 %! t = time (); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
293 %! assert (fix (mktime (localtime (t))) == fix (t)); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
294 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
295 ## These tests fail on systems with mktime functions of limited |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
296 ## intelligence: |
11005
0de4eff677d6
use mktime module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
297 %!assert (datestr (datenum (1969, 1, 1), 0), "01-Jan-1969 00:00:00") |
0de4eff677d6
use mktime module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
298 %!assert (datestr (datenum (1901, 1, 1), 0), "01-Jan-1901 00:00:00") |
0de4eff677d6
use mktime module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
299 %!assert (datestr (datenum (1795, 1, 1), 0), "01-Jan-1795 00:00:00") |
0de4eff677d6
use mktime module from gnulib
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
300 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
301 %!error mktime () |
19142
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
302 %!error mktime (1) |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
303 %!error mktime (1, 2, 3) |
19142
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
304 %!error mktime (struct ("year", "foo")) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
305 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
306 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
307 DEFUN (strftime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
308 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
309 @deftypefn {Built-in Function} {} strftime (@var{fmt}, @var{tm_struct})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
310 Format the time structure @var{tm_struct} in a flexible way using the format\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
311 string @var{fmt} that contains @samp{%} substitutions similar to those in\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
312 @code{printf}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
313 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
314 Except where noted, substituted fields have a fixed size; numeric fields are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
315 padded if necessary. Padding is with zeros by default; for fields that\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
316 display a single number, padding can be changed or inhibited by following\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
317 the @samp{%} with one of the modifiers described below. Unknown field\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
318 specifiers are copied as normal characters. All other characters are copied\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
319 to the output without change. For example:\n\ |
2928 | 320 \n\ |
3295 | 321 @example\n\ |
322 @group\n\ | |
5020 | 323 strftime (\"%r (%Z) %A %e %B %Y\", localtime (time ()))\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
324 @result{} \"01:15:06 AM (CST) Monday 17 February 1997\"\n\ |
3295 | 325 @end group\n\ |
326 @end example\n\ | |
2928 | 327 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
328 Octave's @code{strftime} function supports a superset of the ANSI C field\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
329 specifiers.\n\ |
2928 | 330 \n\ |
3295 | 331 @noindent\n\ |
2928 | 332 Literal character fields:\n\ |
333 \n\ | |
3295 | 334 @table @code\n\ |
12776
944cf42c699e
doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
335 @item %%\n\ |
3295 | 336 % character.\n\ |
2928 | 337 \n\ |
12776
944cf42c699e
doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
338 @item %n\n\ |
3295 | 339 Newline character.\n\ |
340 \n\ | |
12776
944cf42c699e
doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
341 @item %t\n\ |
3295 | 342 Tab character.\n\ |
343 @end table\n\ | |
344 \n\ | |
345 @noindent\n\ | |
2928 | 346 Numeric modifiers (a nonstandard extension):\n\ |
347 \n\ | |
3295 | 348 @table @code\n\ |
349 @item - (dash)\n\ | |
350 Do not pad the field.\n\ | |
2928 | 351 \n\ |
3295 | 352 @item _ (underscore)\n\ |
353 Pad the field with spaces.\n\ | |
354 @end table\n\ | |
355 \n\ | |
356 @noindent\n\ | |
2928 | 357 Time fields:\n\ |
358 \n\ | |
3295 | 359 @table @code\n\ |
360 @item %H\n\ | |
361 Hour (00-23).\n\ | |
362 \n\ | |
363 @item %I\n\ | |
364 Hour (01-12).\n\ | |
365 \n\ | |
366 @item %k\n\ | |
367 Hour (0-23).\n\ | |
368 \n\ | |
369 @item %l\n\ | |
370 Hour (1-12).\n\ | |
371 \n\ | |
372 @item %M\n\ | |
373 Minute (00-59).\n\ | |
374 \n\ | |
375 @item %p\n\ | |
376 Locale's AM or PM.\n\ | |
2928 | 377 \n\ |
3295 | 378 @item %r\n\ |
379 Time, 12-hour (hh:mm:ss [AP]M).\n\ | |
380 \n\ | |
381 @item %R\n\ | |
382 Time, 24-hour (hh:mm).\n\ | |
383 \n\ | |
384 @item %s\n\ | |
385 Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).\n\ | |
386 \n\ | |
387 @item %S\n\ | |
388 Second (00-61).\n\ | |
389 \n\ | |
390 @item %T\n\ | |
391 Time, 24-hour (hh:mm:ss).\n\ | |
392 \n\ | |
393 @item %X\n\ | |
394 Locale's time representation (%H:%M:%S).\n\ | |
395 \n\ | |
20375
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
396 @item %z\n\ |
20719
d903cccb8de8
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
397 Offset from UTC (±@nospell{hhmm}), or nothing if no time zone is\n\ |
d903cccb8de8
doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
398 determinable.\n\ |
20375
31f89b12aaf7
strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents:
20172
diff
changeset
|
399 \n\ |
3295 | 400 @item %Z\n\ |
401 Time zone (EDT), or nothing if no time zone is determinable.\n\ | |
402 @end table\n\ | |
403 \n\ | |
404 @noindent\n\ | |
2928 | 405 Date fields:\n\ |
406 \n\ | |
3295 | 407 @table @code\n\ |
408 @item %a\n\ | |
409 Locale's abbreviated weekday name (Sun-Sat).\n\ | |
410 \n\ | |
411 @item %A\n\ | |
412 Locale's full weekday name, variable length (Sunday-Saturday).\n\ | |
413 \n\ | |
414 @item %b\n\ | |
415 Locale's abbreviated month name (Jan-Dec).\n\ | |
416 \n\ | |
417 @item %B\n\ | |
418 Locale's full month name, variable length (January-December).\n\ | |
419 \n\ | |
420 @item %c\n\ | |
421 Locale's date and time (Sat Nov 04 12:02:33 EST 1989).\n\ | |
422 \n\ | |
423 @item %C\n\ | |
424 Century (00-99).\n\ | |
425 \n\ | |
426 @item %d\n\ | |
427 Day of month (01-31).\n\ | |
428 \n\ | |
429 @item %e\n\ | |
430 Day of month ( 1-31).\n\ | |
431 \n\ | |
432 @item %D\n\ | |
433 Date (mm/dd/yy).\n\ | |
434 \n\ | |
435 @item %h\n\ | |
436 Same as %b.\n\ | |
437 \n\ | |
438 @item %j\n\ | |
439 Day of year (001-366).\n\ | |
440 \n\ | |
441 @item %m\n\ | |
442 Month (01-12).\n\ | |
443 \n\ | |
444 @item %U\n\ | |
445 Week number of year with Sunday as first day of week (00-53).\n\ | |
446 \n\ | |
447 @item %w\n\ | |
448 Day of week (0-6).\n\ | |
449 \n\ | |
450 @item %W\n\ | |
451 Week number of year with Monday as first day of week (00-53).\n\ | |
452 \n\ | |
453 @item %x\n\ | |
454 Locale's date representation (mm/dd/yy).\n\ | |
455 \n\ | |
456 @item %y\n\ | |
457 Last two digits of year (00-99).\n\ | |
458 \n\ | |
459 @item %Y\n\ | |
460 Year (1970-).\n\ | |
461 @end table\n\ | |
5688 | 462 @seealso{strptime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
5646 | 463 @end deftypefn") |
2928 | 464 { |
3465 | 465 octave_value retval; |
2928 | 466 |
3254 | 467 if (args.length () == 2) |
2928 | 468 { |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20581
diff
changeset
|
469 std::string fmt = args(0).xstring_value ("strftime: FMT must be a string"); |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
470 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
471 octave_scalar_map map = args(1).xscalar_map_value ("strftime: TM_STRUCT must be a structure"); |
2928 | 472 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
473 octave_base_tm tm = extract_tm (map, "strftime"); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
474 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
475 retval = tm.strftime (fmt); |
2928 | 476 } |
477 else | |
5823 | 478 print_usage (); |
2928 | 479 |
480 return retval; | |
481 } | |
482 | |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
483 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
484 %!assert (ischar (strftime ("%%%n%t%H%I%k%l", localtime (time ())))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
485 %!assert (ischar (strftime ("%M%p%r%R%s%S%T", localtime (time ())))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
486 %!assert (ischar (strftime ("%X%Z%z%a%A%b%B", localtime (time ())))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
487 %!assert (ischar (strftime ("%c%C%d%e%D%h%j", localtime (time ())))); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
488 %!assert (ischar (strftime ("%m%U%w%W%x%y%Y", localtime (time ())))); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
489 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
490 %!error strftime () |
19142
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
491 %!error strftime ("foo", 1) |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
492 %!error strftime ("foo", struct ("year", "foo")) |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
493 %!error strftime ("foo", localtime (time ()), 1) |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
494 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7097
diff
changeset
|
495 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
496 DEFUN (strptime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
497 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14501
diff
changeset
|
498 @deftypefn {Built-in Function} {[@var{tm_struct}, @var{nchars}] =} strptime (@var{str}, @var{fmt})\n\ |
5675 | 499 Convert the string @var{str} to the time structure @var{tm_struct} under\n\ |
500 the control of the format string @var{fmt}.\n\ | |
501 \n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
502 If @var{fmt} fails to match, @var{nchars} is 0; otherwise, it is set to the\n\ |
5675 | 503 position of last matched character plus 1. Always check for this unless\n\ |
504 you're absolutely sure the date string will be parsed correctly.\n\ | |
5688 | 505 @seealso{strftime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\ |
3465 | 506 @end deftypefn") |
507 { | |
508 octave_value_list retval; | |
509 | |
510 if (args.length () == 2) | |
511 { | |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20581
diff
changeset
|
512 std::string str = args(0).xstring_value ("strptime: argument STR must be a string"); |
3465 | 513 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20581
diff
changeset
|
514 std::string fmt = args(1).xstring_value ("strptime: FMT must be a string"); |
19403
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19142
diff
changeset
|
515 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
516 octave_strptime t (str, fmt); |
3465 | 517 |
20581
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
518 retval(1) = t.characters_converted (); |
fd0efcdb3718
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
519 retval(0) = octave_value (mk_tm_map (t)); |
3465 | 520 } |
521 else | |
5823 | 522 print_usage (); |
3465 | 523 |
524 return retval; | |
525 } | |
19142
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
526 |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
527 /* |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
528 %!test |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
529 %! fmt = "%Y-%m-%d %H:%M:%S"; |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
530 %! s = strftime (fmt, localtime (time ())); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
531 %! ts = strptime (s, fmt); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
532 %! assert (isstruct (ts)); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
533 %! assert (isfield (ts, "usec")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
534 %! assert (isfield (ts, "year")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
535 %! assert (isfield (ts, "mon")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
536 %! assert (isfield (ts, "mday")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
537 %! assert (isfield (ts, "sec")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
538 %! assert (isfield (ts, "min")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
539 %! assert (isfield (ts, "wday")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
540 %! assert (isfield (ts, "hour")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
541 %! assert (isfield (ts, "isdst")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
542 %! assert (isfield (ts, "yday")); |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
543 |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
544 %!error strptime () |
b8bd0b55af45
codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents:
17787
diff
changeset
|
545 */ |