annotate liboctave/system/oct-time.cc @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents f2f386d431ff
children 243b51ec9ff0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30083
diff changeset
3 // Copyright (C) 1999-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21562
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21218
diff changeset
27 # include "config.h"
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
28 #endif
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
29
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
30 #include <cmath>
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
31 #include <ctime>
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
32
23676
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
33 #include <iomanip>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
34 #include <limits>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
35 #include <ostream>
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15020
diff changeset
36
29138
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
37 #if defined (OCTAVE_USE_WINDOWS_API)
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
38 # include <windows.h>
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
39 #endif
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
40
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
41 #include "lo-error.h"
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
42 #include "lo-utils.h"
29138
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
43 #include "lo-sysdep.h"
13975
16158606112d avoid memory error in strptime
John W. Eaton <jwe@octave.org>
parents: 13974
diff changeset
44 #include "oct-locbuf.h"
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
45 #include "oct-time.h"
23676
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
46 #include "octave-preserve-stream-state.h"
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
47 #include "strftime-wrapper.h"
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
48 #include "strptime-wrapper.h"
21930
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
49 #include "time-wrappers.h"
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
50
21734
11af9c03400c write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
51 namespace octave
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
52 {
21734
11af9c03400c write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents: 21730
diff changeset
53 namespace sys
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
54 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
55 time::time (double d)
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
56 : m_ot_unix_time (static_cast<time_t> (d)), m_ot_usec (0)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
57 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
58 double ip;
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
59 m_ot_usec = static_cast<int> (std::modf (d, &ip) * 1e6);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
60 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
61
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
62 time::time (const base_tm& tm)
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
63 : m_ot_unix_time (), m_ot_usec ()
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
64 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
65 struct ::tm t;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
66
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
67 t.tm_sec = tm.sec ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
68 t.tm_min = tm.min ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
69 t.tm_hour = tm.hour ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
70 t.tm_mday = tm.mday ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
71 t.tm_mon = tm.mon ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
72 t.tm_year = tm.year ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
73 t.tm_wday = tm.wday ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
74 t.tm_yday = tm.yday ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
75 t.tm_isdst = tm.isdst ();
13984
1126c2907878 avoid accessing tm_gmtoff from struct tm unless it is present
John W. Eaton <jwe@octave.org>
parents: 13982
diff changeset
76
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 19697
diff changeset
77 #if defined (HAVE_TM_GMTOFF)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
78 t.tm_gmtoff = tm.gmtoff ();
13984
1126c2907878 avoid accessing tm_gmtoff from struct tm unless it is present
John W. Eaton <jwe@octave.org>
parents: 13982
diff changeset
79 #endif
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
80
3887
7da18459c08b [project @ 2002-04-04 00:44:21 by jwe]
jwe
parents: 3736
diff changeset
81 #if defined (HAVE_STRUCT_TM_TM_ZONE)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
82 std::string s = tm.zone ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
83 char *ps = strsave (s.c_str ());
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
84 t.tm_zone = ps;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
85 #endif
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
86
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
87 m_ot_unix_time = octave_mktime_wrapper (&t);
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
88
3887
7da18459c08b [project @ 2002-04-04 00:44:21 by jwe]
jwe
parents: 3736
diff changeset
89 #if defined (HAVE_STRUCT_TM_TM_ZONE)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
90 delete [] ps;
3344
ff13d5dec62d [project @ 1999-11-08 04:18:48 by jwe]
jwe
parents: 3322
diff changeset
91 #endif
ff13d5dec62d [project @ 1999-11-08 04:18:48 by jwe]
jwe
parents: 3322
diff changeset
92
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
93 m_ot_usec = tm.usec ();
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
94 }
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
95
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
96 std::string
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
97 time::ctime (void) const
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
98 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21734
diff changeset
99 return localtime (*this).asctime ();
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
100 }
3255
4d33b1e56bff [project @ 1999-07-15 20:54:14 by jwe]
jwe
parents: 3253
diff changeset
101
23676
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
102 std::ostream&
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
103 operator << (std::ostream& os, const time& ot)
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
104 {
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
105 preserve_stream_state stream_state (os);
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
106
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
107 os << ot.m_ot_unix_time << '.'
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
108 << std::setw (6) << std::setfill ('0') << ot.m_ot_usec;
23676
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
109
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
110 return os;
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
111 }
e719f04a5707 new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
112
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
113 void
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
114 time::stamp (void)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
115 {
30070
2d662df32969 maint: use "m_" prefix for member variables in class time.
Rik <rik@octave.org>
parents: 29655
diff changeset
116 octave_gettimeofday_wrapper (&m_ot_unix_time, &m_ot_usec);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
117 }
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
118
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
119 // From the mktime() manual page:
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
120 //
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
121 // The mktime() function converts a broken-down time structure,
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
122 // expressed as local time, to calendar time representation.
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
123 //
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
124 // <snip>
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
125 //
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
126 // If structure members are outside their legal interval, they
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
127 // will be normalized (so that, e.g., 40 October is changed into
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
128 // 9 November).
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
129 //
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
130 // So, we no longer check limits here.
3736
ac4609ffc702 [project @ 2000-11-16 17:25:34 by jwe]
jwe
parents: 3709
diff changeset
131
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
132 #define DEFINE_SET_FIELD_FCN(type, f, lo, hi) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22062
diff changeset
133 base_tm& \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22062
diff changeset
134 base_tm::f (type v) \
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
135 { \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22062
diff changeset
136 m_ ## f = v; \
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
137 \
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
138 return *this; \
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
139 }
13974
f5bd61eb032f handle tm_gmtoff field in struct tm
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
140
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
141 #define DEFINE_SET_INT_FIELD_FCN(f, lo, hi) \
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
142 DEFINE_SET_FIELD_FCN (int, f, lo, hi)
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
143
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
144 DEFINE_SET_INT_FIELD_FCN (usec, 0, 1000000)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 DEFINE_SET_INT_FIELD_FCN (sec, 0, 61)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
146 DEFINE_SET_INT_FIELD_FCN (min, 0, 59)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
147 DEFINE_SET_INT_FIELD_FCN (hour, 0, 23)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
148 DEFINE_SET_INT_FIELD_FCN (mday, 1, 31)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
149 DEFINE_SET_INT_FIELD_FCN (mon, 0, 11)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
150 DEFINE_SET_INT_FIELD_FCN (year, std::numeric_limits<int>::min (),
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
151 std::numeric_limitd<int>::max ())
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
152 DEFINE_SET_INT_FIELD_FCN (wday, 0, 6)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
153 DEFINE_SET_INT_FIELD_FCN (yday, 0, 365)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
154 DEFINE_SET_INT_FIELD_FCN (isdst, 0, 1)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
155 DEFINE_SET_FIELD_FCN (long, gmtoff, -86400, 0)
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
156
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
157 base_tm&
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
158 base_tm::zone (const std::string& s)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
159 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
160 m_zone = s;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
161 return *this;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
162 }
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
163
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20375
diff changeset
164 #if ! defined STRFTIME_BUF_INITIAL_SIZE
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 20791
diff changeset
165 # define STRFTIME_BUF_INITIAL_SIZE 128
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
166 #endif
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
167
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
168 std::string
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
169 base_tm::strftime (const std::string& fmt) const
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
170 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
171 std::string retval;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
172
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
173 if (! fmt.empty ())
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
174 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
175 struct ::tm t;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
176
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
177 t.tm_sec = m_sec;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
178 t.tm_min = m_min;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
179 t.tm_hour = m_hour;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
180 t.tm_mday = m_mday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
181 t.tm_mon = m_mon;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
182 t.tm_year = m_year;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
183 t.tm_wday = m_wday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
184 t.tm_yday = m_yday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
185 t.tm_isdst = m_isdst;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
186
20375
31f89b12aaf7 strftime: Add support for "%z" conversion specifier (bug #45592)
Mike Miller <mtmiller@octave.org>
parents: 19697
diff changeset
187 #if defined (HAVE_TM_GMTOFF)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
188 t.tm_gmtoff = m_gmtoff;
13974
f5bd61eb032f handle tm_gmtoff field in struct tm
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
189 #endif
f5bd61eb032f handle tm_gmtoff field in struct tm
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
190
3887
7da18459c08b [project @ 2002-04-04 00:44:21 by jwe]
jwe
parents: 3736
diff changeset
191 #if defined (HAVE_STRUCT_TM_TM_ZONE)
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
192 char *ps = strsave (m_zone.c_str ());
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
193 t.tm_zone = ps;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
194 #endif
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
195
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
196 const char *fmt_str = fmt.c_str ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
197
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23447
diff changeset
198 char *buf = nullptr;
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
199 std::size_t bufsize = STRFTIME_BUF_INITIAL_SIZE;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
200 std::size_t chars_written = 0;
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
201
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
202 while (chars_written == 0)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
203 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
204 delete [] buf;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
205 buf = new char [bufsize];
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
206 buf[0] = '\0';
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
207
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
208 chars_written
24103
c995cbb22422 rewrite strftime wrapper to match standard library definition
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
209 = octave_strftime_wrapper (buf, bufsize, fmt_str, &t);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
210
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
211 bufsize *= 2;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
212 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
213
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
214 #if defined (HAVE_STRUCT_TM_TM_ZONE)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
215 delete [] ps;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
216 #endif
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
217
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
218 retval = buf;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
219
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
220 delete [] buf;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
221 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
222
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
223 return retval;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
224 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
225
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
226 void
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
227 base_tm::init (void *p)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
228 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
229 if (! p)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
230 return;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
231
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23220
diff changeset
232 struct ::tm *t = static_cast<struct ::tm *> (p);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
233
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
234 m_sec = t->tm_sec;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
235 m_min = t->tm_min;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
236 m_hour = t->tm_hour;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
237 m_mday = t->tm_mday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
238 m_mon = t->tm_mon;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
239 m_year = t->tm_year;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
240 m_wday = t->tm_wday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
241 m_yday = t->tm_yday;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
242 m_isdst = t->tm_isdst;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
243
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
244 #if defined (HAVE_TM_GMTOFF)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
245 m_gmtoff = t->tm_gmtoff;
29138
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
246 #elif defined (OCTAVE_USE_WINDOWS_API)
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
247 TIME_ZONE_INFORMATION tzi;
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
248
29354
6c2fa2293242 Increase Windows API version to Windows 7 (bug #60014).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29138
diff changeset
249 GetTimeZoneInformationForYear (m_year, nullptr, &tzi);
29138
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
250
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
251 if (m_isdst)
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
252 m_gmtoff = -60 * (tzi.Bias + tzi.DaylightBias);
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
253 else
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
254 m_gmtoff = -60 * (tzi.Bias + tzi.StandardBias);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
255 #endif
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
256
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
257 #if defined (HAVE_STRUCT_TM_TM_ZONE)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
258 if (t->tm_zone)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
259 m_zone = t->tm_zone;
29138
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
260 #elif defined (OCTAVE_USE_WINDOWS_API)
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
261 if (m_isdst)
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
262 m_zone = sys::u8_from_wstring (tzi.DaylightName);
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
263 else
eacd1a3417c3 time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27923
diff changeset
264 m_zone = sys::u8_from_wstring (tzi.StandardName);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
265 #elif defined (HAVE_TZNAME)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
266 if (t->tm_isdst == 0 || t->tm_isdst == 1)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
267 m_zone = tzname[t->tm_isdst];
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
268 #endif
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
269 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
270
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
271 void
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
272 localtime::init (const time& ot)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
273 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
274 m_usec = ot.usec ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
275
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
276 time_t t = ot.unix_time ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
277
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21930
diff changeset
278 base_tm::init (std::localtime (&t));
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
279 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
280
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
281 void
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
282 gmtime::init (const time& ot)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
283 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
284 m_usec = ot.usec ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
285
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
286 time_t t = ot.unix_time ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
287
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21930
diff changeset
288 base_tm::init (std::gmtime (&t));
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
289 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
290
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
291 void
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
292 strptime::init (const std::string& str, const std::string& fmt)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
293 {
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
294 struct ::tm t;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
295
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
296 t.tm_sec = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
297 t.tm_min = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
298 t.tm_hour = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
299 t.tm_mday = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
300 t.tm_mon = -1;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
301 t.tm_year = std::numeric_limits<int>::min ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
302 t.tm_wday = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
303 t.tm_yday = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
304 t.tm_isdst = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
305
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
306 #if defined (HAVE_TM_GMTOFF)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
307 t.tm_gmtoff = 0;
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
308 #endif
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
309
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
310 #if defined (HAVE_STRUCT_TM_TM_ZONE)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
311 char *ps = strsave ("");
3709
c73bea82af94 [project @ 2000-08-02 02:23:26 by jwe]
jwe
parents: 3706
diff changeset
312 t.tm_zone = ps;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
313 #endif
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
314
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
315 const char *p = str.c_str ();
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
316
21888
00f1249f2483 create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents: 21852
diff changeset
317 char *q = octave_strptime_wrapper (p, fmt.c_str (), &t);
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
318
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
319 // Fill in wday and yday, but only if mday is valid and the mon and year
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
320 // are filled in, avoiding issues with mktime and invalid dates.
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
321 if (t.tm_mday != 0 && t.tm_mon >= 0
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
322 && t.tm_year != std::numeric_limits<int>::min ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10279
diff changeset
323 {
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
324 t.tm_isdst = -1;
22062
d18aad835ad6 provide wrapper for gnulib mktime function
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
325 octave_mktime_wrapper (&t);
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
326 }
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
327
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
328 if (t.tm_mon < 0)
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
329 t.tm_mon = 0;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
330
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
331 if (t.tm_year == std::numeric_limits<int>::min ())
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
332 t.tm_year = 0;
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
333
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
334 if (q)
30083
f2f386d431ff maint: use "m_" prefix for member variables in class strptime.
Rik <rik@octave.org>
parents: 30070
diff changeset
335 m_nchars = q - p + 1;
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
336 else
30083
f2f386d431ff maint: use "m_" prefix for member variables in class strptime.
Rik <rik@octave.org>
parents: 30070
diff changeset
337 m_nchars = 0;
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
338
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
339 base_tm::init (&t);
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
340
3887
7da18459c08b [project @ 2002-04-04 00:44:21 by jwe]
jwe
parents: 3736
diff changeset
341 #if defined (HAVE_STRUCT_TM_TM_ZONE)
3709
c73bea82af94 [project @ 2000-08-02 02:23:26 by jwe]
jwe
parents: 3706
diff changeset
342 delete [] ps;
3344
ff13d5dec62d [project @ 1999-11-08 04:18:48 by jwe]
jwe
parents: 3322
diff changeset
343 #endif
3709
c73bea82af94 [project @ 2000-08-02 02:23:26 by jwe]
jwe
parents: 3706
diff changeset
344 }
21930
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
345
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
346 void
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
347 cpu_time::stamp (void)
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
348 {
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
349 octave_cpu_time (&m_usr_sec, &m_sys_sec, &m_usr_usec, &m_sys_usec);
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
350 }
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
351
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
352 void
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
353 resource_usage::stamp (void)
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
354 {
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
355 time_t usr_sec, sys_sec;
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
356 long usr_usec, sys_usec;
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
357
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
358 octave_getrusage_wrapper (&usr_sec, &sys_sec, &usr_usec,
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
359 &sys_usec, &m_maxrss, &m_ixrss,
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
360 &m_idrss, &m_isrss, &m_minflt,
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
361 &m_majflt, &m_nswap, &m_inblock,
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
362 &m_oublock, &m_msgsnd, &m_msgrcv,
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
363 &m_nsignals, &m_nvcsw, &m_nivcsw);
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
364
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
365 m_cpu = cpu_time (usr_sec, sys_sec, usr_usec, sys_usec);
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
366 }
21730
30c53770f47e use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
367 }
3253
07d2d307c43e [project @ 1999-07-15 15:58:50 by jwe]
jwe
parents:
diff changeset
368 }