annotate src/corefcn/time.cc @ 15039:e753177cde93

maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory * __contourc__.cc, __dispatch__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bsxfun.cc, cellfun.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, det.cc, dlmread.cc, dot.cc, eig.cc, fft.cc, fft2.cc, fftn.cc, filter.cc, find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, hess.cc, hex2num.cc, inv.cc, kron.cc, lookup.cc, lsode.cc, lu.cc, luinc.cc, matrix_type.cc, max.cc, md5sum.cc, mgorth.cc, nproc.cc, pinv.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, sub2ind.cc, svd.cc, syl.cc, time.cc, tril.cc, typecast.cc: Move functions from DLD-FUNCTIONS/ to corefcn/ directory. Include "defun.h", not "defun-dld.h". Change docstring to refer to these as "Built-in Functions". * build-aux/mk-opts.pl: Generate options code with '#include "defun.h"'. Change option docstrings to refer to these as "Built-in Functions". * corefcn/module.mk: List of functions to build in corefcn/ dir. * DLD-FUNCTIONS/config-module.awk: Update to new build system. * DLD-FUNCTIONS/module-files: Remove functions which are now in corefcn/ directory. * src/Makefile.am: Update to build "convenience library" in corefcn/. Octave program now links against all other libraries + corefcn libary. * src/find-defun-files.sh: Strip $srcdir from filename. * src/link-deps.mk: Add REGEX and FFTW link dependencies for liboctinterp. * type.m, which.m: Change failing tests to use 'amd', still a dynamic function, rather than 'dot', which isn't.
author Rik <rik@octave.org>
date Fri, 27 Jul 2012 15:35:00 -0700
parents src/DLD-FUNCTIONS/time.cc@60e5cf354d80
children
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
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13915
diff changeset
3 Copyright (C) 1996-2012 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 ()));
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4367
diff changeset
53 m.assign ("zone", t.zone ());
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
54
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
55 return m;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
56 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
57
11042
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
58 static inline int
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
59 intfield (const octave_scalar_map& m, const std::string& k)
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
60 {
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
61 int retval = 0;
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
62
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
63 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
64
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
65 if (! v.is_empty ())
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
66 retval = v.int_value ();
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
67
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
68 return retval;
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
69 }
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 static inline std::string
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
72 stringfield (const octave_scalar_map& m, const std::string& k)
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
73 {
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
74 std::string retval;
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
75
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
76 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
77
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
78 if (! v.is_empty ())
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
79 retval = v.string_value ();
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
80
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
81 return retval;
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
82 }
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
83
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
84 static octave_base_tm
11042
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
85 extract_tm (const octave_scalar_map& m)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
86 {
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
87 octave_base_tm tm;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
88
11042
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
89 tm.usec (intfield (m, "usec"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
90 tm.sec (intfield (m, "sec"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
91 tm.min (intfield (m, "min"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
92 tm.hour (intfield (m, "hour"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
93 tm.mday (intfield (m, "mday"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
94 tm.mon (intfield (m, "mon"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
95 tm.year (intfield (m, "year"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
96 tm.wday (intfield (m, "wday"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
97 tm.yday (intfield (m, "yday"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
98 tm.isdst (intfield (m, "isdst"));
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
99 tm.zone (stringfield (m, "zone"));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
100
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
101 return tm;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
102 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
103
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
104 DEFUN (time, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
105 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
106 @deftypefn {Built-in Function} {@var{seconds} =} time ()\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
107 Return the current time as the number of seconds since the epoch. The\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
108 epoch is referenced to 00:00:00 CUT (Coordinated Universal Time) 1 Jan\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
109 1970. For example, on Monday February 17, 1997 at 07:15:06 CUT, the\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
110 value returned by @code{time} was 856163706.\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
111 @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
112 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
113 {
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
114 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
115
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
116 if (args.length () == 0)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7017
diff changeset
117 retval = octave_time ();
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
118 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
119 print_usage ();
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
120
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3254
diff changeset
121 return retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
122 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
123
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
124 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
125 %!assert (time () > 0)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
126 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
127
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
128 DEFUN (gmtime, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
129 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
130 @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
131 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
132 return a time structure corresponding to CUT (Coordinated Universal Time).\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
133 For example:\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
134 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
135 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
136 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
137 gmtime (time ())\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
138 @result{} @{\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
139 usec = 0\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
140 sec = 6\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
141 min = 15\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
142 hour = 7\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
143 mday = 17\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
144 mon = 1\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
145 year = 97\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
146 wday = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
147 yday = 47\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
148 isdst = 0\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
149 zone = CST\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
150 @}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
151 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
152 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
153 @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
154 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
155 {
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
156 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
157
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
158 if (args.length () == 1)
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
159 {
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
160 double tmp = args(0).double_value ();
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
161
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
162 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
163 retval = octave_value (mk_tm_map (octave_gmtime (tmp)));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
164 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
165 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
166 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
167
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
168 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
169 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
170
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
171 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
172 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
173 %! ts = gmtime (time ());
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
174 %! assert (isstruct (ts));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
175 %! assert (isfield (ts, "usec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
176 %! assert (isfield (ts, "year"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
177 %! assert (isfield (ts, "mon"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
178 %! assert (isfield (ts, "mday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
179 %! assert (isfield (ts, "sec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
180 %! assert (isfield (ts, "min"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
181 %! assert (isfield (ts, "wday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
182 %! assert (isfield (ts, "hour"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
183 %! assert (isfield (ts, "isdst"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
184 %! assert (isfield (ts, "yday"));
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
185
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
186 %!error gmtime ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
187 %!error gmtime (1, 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
188 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
189
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
190 DEFUN (localtime, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
191 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
192 @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
193 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
194 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
195 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
196 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
197 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
198 localtime (time ())\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
199 @result{} @{\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
200 usec = 0\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
201 sec = 6\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
202 min = 15\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
203 hour = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
204 mday = 17\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
205 mon = 1\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
206 year = 97\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
207 wday = 1\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
208 yday = 47\n\
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
209 isdst = 0\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
210 zone = CST\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
211 @}\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
212 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
213 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
214 @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
215 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
216 {
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
217 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
218
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
219 if (args.length () == 1)
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 double tmp = args(0).double_value ();
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
222
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
223 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
224 retval = octave_value (mk_tm_map (octave_localtime (tmp)));
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
225 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
226 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
227 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
228
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
229 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
230 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
231
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
232 /*
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
233 %!test
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
234 %! ts = localtime (time ());
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
235 %! assert (isstruct (ts));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
236 %! assert (isfield (ts, "usec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
237 %! assert (isfield (ts, "year"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
238 %! assert (isfield (ts, "mon"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
239 %! assert (isfield (ts, "mday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
240 %! assert (isfield (ts, "sec"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
241 %! assert (isfield (ts, "min"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
242 %! assert (isfield (ts, "wday"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
243 %! assert (isfield (ts, "hour"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
244 %! assert (isfield (ts, "isdst"));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
245 %! assert (isfield (ts, "yday"));
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
246
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
247 %!error localtime ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
248 %!error localtime (1, 2)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
249 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
250
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
251 DEFUN (mktime, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
252 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
253 @deftypefn {Built-in Function} {@var{seconds} =} mktime (@var{tm_struct})\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
254 Convert a time structure corresponding to the local time to the number\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10231
diff changeset
255 of seconds since the epoch. For example:\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
256 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
257 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
258 @group\n\
7097
e8c94e473c68 [project @ 2007-11-02 17:24:23 by jwe]
jwe
parents: 7065
diff changeset
259 mktime (localtime (time ()))\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
260 @result{} 856163706\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
261 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3295
diff changeset
262 @end example\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
263 @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
264 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
265 {
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
266 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
267
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
268 if (args.length () == 1)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
269 {
11042
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
270 octave_scalar_map map = args(0).scalar_map_value ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
271
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
272 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
273 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
274 octave_base_tm tm = extract_tm (map);
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
275
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
276 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
277 retval = octave_time (tm);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
278 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
279 error ("mktime: invalid TM_STRUCT argument");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
280 }
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
281 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
282 error ("mktime: TM_STRUCT argument must be a structure");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
283 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
284 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
285 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
286
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
287 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
288 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
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 ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
302 %!error mktime (1, 2, 3)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
303 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
304
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
305 DEFUN (strftime, args, ,
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
306 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
307 @deftypefn {Built-in Function} {} strftime (@var{fmt}, @var{tm_struct})\n\
5675
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
308 Format the time structure @var{tm_struct} in a flexible way using the\n\
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
309 format string @var{fmt} that contains @samp{%} substitutions\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
310 similar to those in @code{printf}. Except where noted, substituted\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
311 fields have a fixed size; numeric fields are padded if necessary.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
312 Padding is with zeros by default; for fields that display a single\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
313 number, padding can be changed or inhibited by following the @samp{%}\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
314 with one of the modifiers described below. Unknown field specifiers are\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
315 copied as normal characters. All other characters are copied to the\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10231
diff changeset
316 output without change. For example:\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
317 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
318 @example\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
319 @group\n\
5020
a6d935b36b7f [project @ 2004-09-22 12:38:10 by jwe]
jwe
parents: 5016
diff changeset
320 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
321 @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
322 @end group\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
323 @end example\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
324 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
325 Octave's @code{strftime} function supports a superset of the ANSI C\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
326 field specifiers.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
327 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
328 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
329 Literal character fields:\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
330 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
331 @table @code\n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
332 @item %%\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
333 % character.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
334 \n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
335 @item %n\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
336 Newline character.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
337 \n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
338 @item %t\n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
339 Tab character.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
340 @end table\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
341 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
342 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
343 Numeric modifiers (a nonstandard extension):\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
344 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
345 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
346 @item - (dash)\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
347 Do not pad the field.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
348 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
349 @item _ (underscore)\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
350 Pad the field with spaces.\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
351 @end table\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 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
354 Time fields:\n\
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 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
357 @item %H\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
358 Hour (00-23).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
359 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
360 @item %I\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
361 Hour (01-12).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
362 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
363 @item %k\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
364 Hour (0-23).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
365 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
366 @item %l\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
367 Hour (1-12).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
368 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
369 @item %M\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
370 Minute (00-59).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
371 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
372 @item %p\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
373 Locale's AM or PM.\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
374 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
375 @item %r\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
376 Time, 12-hour (hh:mm:ss [AP]M).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
377 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
378 @item %R\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
379 Time, 24-hour (hh:mm).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
380 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
381 @item %s\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
382 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
383 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
384 @item %S\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
385 Second (00-61).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
386 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
387 @item %T\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
388 Time, 24-hour (hh:mm:ss).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
389 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
390 @item %X\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
391 Locale's time representation (%H:%M:%S).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
392 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
393 @item %Z\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
394 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
395 @end table\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
396 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
397 @noindent\n\
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
398 Date fields:\n\
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
399 \n\
3295
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
400 @table @code\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
401 @item %a\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
402 Locale's abbreviated weekday name (Sun-Sat).\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 %A\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
405 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
406 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
407 @item %b\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
408 Locale's abbreviated month name (Jan-Dec).\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 %B\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
411 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
412 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
413 @item %c\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
414 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
415 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
416 @item %C\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
417 Century (00-99).\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 %d\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
420 Day of month (01-31).\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 %e\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
423 Day of month ( 1-31).\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 %D\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
426 Date (mm/dd/yy).\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 %h\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
429 Same as %b.\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 %j\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
432 Day of year (001-366).\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 %m\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
435 Month (01-12).\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 %U\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
438 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
439 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
440 @item %w\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
441 Day of week (0-6).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
442 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
443 @item %W\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
444 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
445 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
446 @item %x\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
447 Locale's date representation (mm/dd/yy).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
448 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
449 @item %y\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
450 Last two digits of year (00-99).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
451 \n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
452 @item %Y\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
453 Year (1970-).\n\
35a6d027772c [project @ 1999-10-19 10:13:02 by jwe]
jwe
parents: 3255
diff changeset
454 @end table\n\
5688
6274256266d9 [project @ 2006-03-16 20:36:28 by jwe]
jwe
parents: 5675
diff changeset
455 @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
456 @end deftypefn")
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
457 {
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
458 octave_value retval;
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
459
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
460 if (args.length () == 2)
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
461 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3465
diff changeset
462 std::string fmt = args(0).string_value ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
463
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
464 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
465 {
11042
f6b7b6e5b8b8 time.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 11005
diff changeset
466 octave_scalar_map map = args(1).scalar_map_value ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
467
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
468 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
469 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
470 octave_base_tm tm = extract_tm (map);
3233
98d0ee053ba4 [project @ 1999-01-27 20:23:40 by jwe]
jwe
parents: 3014
diff changeset
471
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
472 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
473 retval = tm.strftime (fmt);
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
474 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
475 error ("strftime: invalid TM_STRUCT argument");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
476 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
477 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
478 error ("strftime: TM_STRUCT must be a structure");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
479 }
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents: 3233
diff changeset
480 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
481 error ("strftime: FMT must be a string");
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
482 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
483 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
484 print_usage ();
2928
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
485
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
486 return retval;
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
487 }
295f037b4b3e [project @ 1997-05-05 05:32:33 by jwe]
jwe
parents:
diff changeset
488
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 %!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
491 %!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
492 %!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
493 %!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
494 %!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
495
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
496 %!error strftime ()
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
497 %!error strftime ("foo", localtime (time ()), 1)
7562
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
498 */
c827f5673321 move tests to individual source files
John W. Eaton <jwe@octave.org>
parents: 7097
diff changeset
499
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
500 DEFUN (strptime, args, ,
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
501 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14501
diff changeset
502 @deftypefn {Built-in Function} {[@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
503 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
504 the control of the format string @var{fmt}.\n\
c5f6623514c4 [project @ 2006-03-16 03:59:09 by jwe]
jwe
parents: 5646
diff changeset
505 \n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
506 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
507 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
508 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
509 @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
510 @end deftypefn")
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
511 {
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
512 octave_value_list retval;
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
513
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
514 if (args.length () == 2)
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
515 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3465
diff changeset
516 std::string str = args(0).string_value ();
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
517
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
518 if (! error_state)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
519 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
520 std::string fmt = args(1).string_value ();
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
521
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
522 if (! error_state)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
523 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
524 octave_strptime t (str, fmt);
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
525
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
526 retval(1) = t.characters_converted ();
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
527 retval(0) = octave_value (mk_tm_map (t));
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
528 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
529 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
530 error ("strptime: FMT must be a string");
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9209
diff changeset
531 }
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
532 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
533 error ("strptime: argument STR must be a string");
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
534 }
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
535 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5688
diff changeset
536 print_usage ();
3465
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
537
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
538 return retval;
996bb7ea4507 [project @ 2000-01-21 07:48:25 by jwe]
jwe
parents: 3325
diff changeset
539 }