annotate libinterp/corefcn/time.cc @ 20939:b17fda023ca6

maint: Use new C++ archetype in more files. Place input validation first in files. Move declaration of retval down in function to be closer to point of usage. Eliminate else clause after if () error. Use "return ovl()" where it makes sense. * find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, graphics.cc, help.cc, hess.cc, hex2num.cc, input.cc, kron.cc, load-path.cc, load-save.cc, lookup.cc, mappers.cc, matrix_type.cc, mgorth.cc, nproc.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, profiler.cc, psi.cc, quad.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc, __eigs__.cc, __glpk__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, chol.cc, colamd.cc, dmperm.cc, fftw.cc, qr.cc, symbfact.cc, symrcm.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-flt-re-mat.cc, ov-java.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc, octave.cc: Use new C++ archetype in more files.
author Rik <rik@octave.org>
date Fri, 18 Dec 2015 15:37:22 -0800
parents 776c0b8c1d07
children 48b2ad5ee801
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
1 /*
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
4
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
6
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
10 option) any later version.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
11
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
15 for more details.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
16
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
19 <http://www.gnu.org/licenses/>.
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
20
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
21 */
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
22
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
25 #endif
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
26
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
27 #include <string>
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
30 #include "error.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
31 #include "oct-map.h"
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
32 #include "oct-time.h"
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
33 #include "ov.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
34 #include "oct-obj.h"
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
35
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
36 // Date and time functions.
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
39 mk_tm_map (const octave_base_tm& t)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
42
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
43 m.assign ("usec", static_cast<double> (t.usec ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
44 m.assign ("sec", static_cast<double> (t.sec ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
45 m.assign ("min", static_cast<double> (t.min ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
46 m.assign ("hour", static_cast<double> (t.hour ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
47 m.assign ("mday", static_cast<double> (t.mday ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
48 m.assign ("mon", static_cast<double> (t.mon ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
49 m.assign ("year", static_cast<double> (t.year ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
50 m.assign ("wday", static_cast<double> (t.wday ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
51 m.assign ("yday", static_cast<double> (t.yday ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
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
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
54 m.assign ("zone", t.zone ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
55
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
56 return m;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
57 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
87 {
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
88 octave_base_tm tm;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
102
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
103 return tm;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
104 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
108 @deftypefn {} {@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
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
114 @seealso{strftime, strptime, localtime, gmtime, mktime, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
115 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
116 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
117 if (args.length () != 0)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
118 print_usage ();
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
119
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20882
diff changeset
120 return ovl (octave_time ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
121 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
122
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
123 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
124 %!assert (time () > 0)
19142
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
125
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
126 %!error time (1)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
127 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
128
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
129 DEFUN (gmtime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
130 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
131 @deftypefn {} {@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
132 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
133 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
134 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
135 For example:\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
136 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
137 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
138 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
139 gmtime (time ())\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
140 @result{} @{\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
141 usec = 0\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
142 sec = 6\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
143 min = 15\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
144 hour = 7\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
145 mday = 17\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
146 mon = 1\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
147 year = 97\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
148 wday = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
149 yday = 47\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
150 isdst = 0\n\
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 20172
diff changeset
151 gmtoff = 0\n\
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 20172
diff changeset
152 zone = GMT\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
153 @}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
154 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
155 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
156 @seealso{strftime, strptime, localtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
157 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
158 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
159 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
160 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
161
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
162 double tmp = args(0).double_value ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
163
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20882
diff changeset
164 return ovl (mk_tm_map (octave_gmtime (tmp)));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
165 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
166
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
167 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
168 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
169 %! ts = gmtime (time ());
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
170 %! assert (isstruct (ts));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
171 %! assert (isfield (ts, "usec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
172 %! assert (isfield (ts, "year"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
173 %! assert (isfield (ts, "mon"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
174 %! assert (isfield (ts, "mday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
175 %! assert (isfield (ts, "sec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
176 %! assert (isfield (ts, "min"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
177 %! assert (isfield (ts, "wday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
178 %! assert (isfield (ts, "hour"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
179 %! assert (isfield (ts, "isdst"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
180 %! assert (isfield (ts, "yday"));
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
181
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
182 %!error gmtime ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
183 %!error gmtime (1, 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
184 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
185
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
186 DEFUN (localtime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
187 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
188 @deftypefn {} {@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
189 Given a value returned from @code{time}, or any non-negative integer,\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
190 return a time structure corresponding to the local time zone.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
191 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
192 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
193 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
194 localtime (time ())\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
195 @result{} @{\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
196 usec = 0\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
197 sec = 6\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
198 min = 15\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
199 hour = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
200 mday = 17\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
201 mon = 1\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
202 year = 97\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
203 wday = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
204 yday = 47\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
205 isdst = 0\n\
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 20172
diff changeset
206 gmtoff = -21600\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
207 zone = CST\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
208 @}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
209 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
210 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
211 @seealso{strftime, strptime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
212 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
213 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
214 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
215 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
216
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
217 double tmp = args(0).double_value ();
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
218
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20882
diff changeset
219 return ovl (mk_tm_map (octave_localtime (tmp)));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
220 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
221
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
222 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
223 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
224 %! ts = localtime (time ());
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
225 %! assert (isstruct (ts));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
226 %! assert (isfield (ts, "usec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
227 %! assert (isfield (ts, "year"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
228 %! assert (isfield (ts, "mon"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
229 %! assert (isfield (ts, "mday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
230 %! assert (isfield (ts, "sec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
231 %! assert (isfield (ts, "min"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
232 %! assert (isfield (ts, "wday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
233 %! assert (isfield (ts, "hour"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
234 %! assert (isfield (ts, "isdst"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
235 %! assert (isfield (ts, "yday"));
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
236
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
237 %!error localtime ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
238 %!error localtime (1, 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
239 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
240
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
241 DEFUN (mktime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
242 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
243 @deftypefn {} {@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
244 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
245 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
246 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
247 For example:\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
248 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
249 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
250 @group\n\
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7065
diff changeset
251 mktime (localtime (time ()))\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
252 @result{} 856163706\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
253 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
254 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
255 @seealso{strftime, strptime, localtime, gmtime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
256 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
257 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
258 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
259 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
260
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
261 octave_scalar_map map = args(0).xscalar_map_value ("mktime: TM_STRUCT argument must be a structure");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
262
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
263 octave_base_tm tm = extract_tm (map, "mktime");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
264
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20882
diff changeset
265 return ovl (octave_time (tm));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
266 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
267
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
268 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
269 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
270 %! t = time ();
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
271 %! 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
272
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
273 ## 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
274 ## intelligence:
11005
0de4eff677d6 use mktime module from gnulib
John W. Eaton <jwe@octave.org>
parents: 10840
diff changeset
275 %!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
276 %!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
277 %!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
278
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
279 %!error mktime ()
19142
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
280 %!error mktime (1)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
281 %!error mktime (1, 2, 3)
19142
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
282 %!error mktime (struct ("year", "foo"))
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
283 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
284
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
285 DEFUN (strftime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
286 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
287 @deftypefn {} {} 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
288 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
289 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
290 @code{printf}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
291 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
292 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
293 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
294 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
295 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
296 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
297 to the output without change. For example:\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
298 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
299 @example\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
300 @group\n\
5020
a6d935b36b7f [project @ 2004-09-22 12:38:10 by jwe]
jwe
parents: 5016
diff changeset
301 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
302 @result{} \"01:15:06 AM (CST) Monday 17 February 1997\"\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
303 @end group\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
304 @end example\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
305 \n\
20172
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
306 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
307 specifiers.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
308 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
309 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
310 Literal character fields:\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
311 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
312 @table @code\n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
313 @item %%\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
314 % character.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
315 \n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
316 @item %n\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
317 Newline character.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
318 \n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
319 @item %t\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
320 Tab character.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
321 @end table\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
322 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
323 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
324 Numeric modifiers (a nonstandard extension):\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
325 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
326 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
327 @item - (dash)\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
328 Do not pad the field.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
329 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
330 @item _ (underscore)\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
331 Pad the field with spaces.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
332 @end table\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
333 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
334 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
335 Time fields:\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
336 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
337 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
338 @item %H\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
339 Hour (00-23).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
340 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
341 @item %I\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
342 Hour (01-12).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
343 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
344 @item %k\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
345 Hour (0-23).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
346 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
347 @item %l\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
348 Hour (1-12).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
349 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
350 @item %M\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
351 Minute (00-59).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
352 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
353 @item %p\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
354 Locale's AM or PM.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
355 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
356 @item %r\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
357 Time, 12-hour (hh:mm:ss [AP]M).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
358 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
359 @item %R\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
360 Time, 24-hour (hh:mm).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
361 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
362 @item %s\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
363 Time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
364 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
365 @item %S\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
366 Second (00-61).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
367 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
368 @item %T\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
369 Time, 24-hour (hh:mm:ss).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
370 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
371 @item %X\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
372 Locale's time representation (%H:%M:%S).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
373 \n\
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 20172
diff changeset
374 @item %z\n\
20719
d903cccb8de8 doc: Periodic spellcheck of documentation.
Rik <rik@octave.org>
parents: 20704
diff changeset
375 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
376 determinable.\n\
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 20172
diff changeset
377 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
378 @item %Z\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
379 Time zone (EDT), or nothing if no time zone is determinable.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
380 @end table\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
381 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
382 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
383 Date fields:\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
384 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
385 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
386 @item %a\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
387 Locale's abbreviated weekday name (Sun-Sat).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
388 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
389 @item %A\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
390 Locale's full weekday name, variable length (Sunday-Saturday).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
391 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
392 @item %b\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
393 Locale's abbreviated month name (Jan-Dec).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
394 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
395 @item %B\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
396 Locale's full month name, variable length (January-December).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
397 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
398 @item %c\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
399 Locale's date and time (Sat Nov 04 12:02:33 EST 1989).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
400 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
401 @item %C\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
402 Century (00-99).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
403 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
404 @item %d\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
405 Day of month (01-31).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
406 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
407 @item %e\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
408 Day of month ( 1-31).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
409 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
410 @item %D\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
411 Date (mm/dd/yy).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
412 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
413 @item %h\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
414 Same as %b.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
415 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
416 @item %j\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
417 Day of year (001-366).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
418 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
419 @item %m\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
420 Month (01-12).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
421 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
422 @item %U\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
423 Week number of year with Sunday as first day of week (00-53).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
424 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
425 @item %w\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
426 Day of week (0-6).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
427 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
428 @item %W\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
429 Week number of year with Monday as first day of week (00-53).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
430 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
431 @item %x\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
432 Locale's date representation (mm/dd/yy).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
433 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
434 @item %y\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
435 Last two digits of year (00-99).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
436 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
437 @item %Y\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
438 Year (1970-).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
439 @end table\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
440 @seealso{strptime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
5646
2b20d1707f29 [project @ 2006-03-06 22:38:32 by jwe]
jwe
parents: 5307
diff changeset
441 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
442 {
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
443 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
444
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
445 if (args.length () != 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
446 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
447
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
448 std::string fmt = args(0).xstring_value ("strftime: FMT must be a string");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
449
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
450 octave_scalar_map map = args(1).xscalar_map_value ("strftime: TM_STRUCT must be a structure");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
451
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
452 octave_base_tm tm = extract_tm (map, "strftime");
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
453
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20882
diff changeset
454 return ovl (tm.strftime (fmt));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
455 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
456
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
457 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
458 %!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
459 %!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
460 %!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
461 %!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
462 %!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
463
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
464 %!error strftime ()
19142
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
465 %!error strftime ("foo", 1)
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
466 %!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
467 %!error strftime ("foo", localtime (time ()), 1)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
468 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
469
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
470 DEFUN (strptime, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
471 "-*- texinfo -*-\n\
20853
1142cf6abc0d 2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents: 20800
diff changeset
472 @deftypefn {} {[@var{tm_struct}, @var{nchars}] =} strptime (@var{str}, @var{fmt})\n\
5675
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
473 Convert the string @var{str} to the time structure @var{tm_struct} under\n\
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
474 the control of the format string @var{fmt}.\n\
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
475 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
476 If @var{fmt} fails to match, @var{nchars} is 0; otherwise, it is set to the\n\
5675
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
477 position of last matched character plus 1. Always check for this unless\n\
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
478 you're absolutely sure the date string will be parsed correctly.\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
479 @seealso{strftime, localtime, gmtime, mktime, time, now, date, clock, datenum, datestr, datevec, calendar, weekday}\n\
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
480 @end deftypefn")
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
481 {
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
482 if (args.length () != 2)
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
483 print_usage ();
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
484
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
485 std::string str = args(0).xstring_value ("strptime: argument STR 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
486
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
487 std::string fmt = args(1).xstring_value ("strptime: FMT must be a string");
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
488
20800
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
489 octave_strptime t (str, fmt);
fb128aafc322 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20719
diff changeset
490
20882
776c0b8c1d07 2015 Code Sprint: time.cc: use ovl ().
Rik <rik@octave.org>
parents: 20880
diff changeset
491 return ovl (mk_tm_map (t), t.characters_converted ());
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
492 }
19142
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
493
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
494 /*
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
495 %!test
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
496 %! fmt = "%Y-%m-%d %H:%M:%S";
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
497 %! s = strftime (fmt, localtime (time ()));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
498 %! ts = strptime (s, fmt);
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
499 %! assert (isstruct (ts));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
500 %! assert (isfield (ts, "usec"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
501 %! assert (isfield (ts, "year"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
502 %! assert (isfield (ts, "mon"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
503 %! assert (isfield (ts, "mday"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
504 %! assert (isfield (ts, "sec"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
505 %! assert (isfield (ts, "min"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
506 %! assert (isfield (ts, "wday"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
507 %! assert (isfield (ts, "hour"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
508 %! assert (isfield (ts, "isdst"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
509 %! assert (isfield (ts, "yday"));
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
510
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
511 %!error strptime ()
b8bd0b55af45 codesprint: Add tests to time handling functions
Mike Miller <mtmiller@ieee.org>
parents: 17787
diff changeset
512 */