Mercurial > octave
annotate liboctave/system/oct-time.cc @ 29138:eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
* liboctave/system/oct-time.cc (base_tm::init): Get time zone offset information
on Windows.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Tue, 01 Dec 2020 22:59:35 +0100 |
parents | bd51beb6205e |
children | 6c2fa2293242 |
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 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1999-2020 The Octave Project Developers |
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 | 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 | 28 #endif |
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 | 41 #include "lo-error.h" |
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 | 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 | 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 | 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) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
56 : ot_unix_time (static_cast<time_t> (d)), ot_usec (0) |
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; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
59 ot_usec = static_cast<int> (std::modf (d, &ip) * 1e6); |
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) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
63 : ot_unix_time (), ot_usec () |
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 | 80 |
3887 | 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 | 85 #endif |
86 | |
22062
d18aad835ad6
provide wrapper for gnulib mktime function
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
87 ot_unix_time = octave_mktime_wrapper (&t); |
3253 | 88 |
3887 | 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 | 91 #endif |
92 | |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
93 ot_usec = tm.usec (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
94 } |
3253 | 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 | 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 |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
107 os << ot.ot_unix_time << '.' |
23676
e719f04a5707
new output stream operator for octave::sys::time objects
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
108 << std::setw (6) << std::setfill ('0') << ot.ot_usec; |
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 { |
21930
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
116 octave_gettimeofday_wrapper (&ot_unix_time, &ot_usec); |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
117 } |
3253 | 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 | 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 | 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 | 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 | 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 | 166 #endif |
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 | 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 | 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 | 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; |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
199 size_t bufsize = STRFTIME_BUF_INITIAL_SIZE; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
200 size_t chars_written = 0; |
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 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
249 // GetTimeZoneInformationForYear is in Windows Vista SP1 or later |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
250 typedef BOOL (WINAPI *gtzify_type) (USHORT year, |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
251 PDYNAMIC_TIME_ZONE_INFORMATION pdtzi, |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
252 LPTIME_ZONE_INFORMATION ptzi); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
253 HMODULE h_kernel32 = LoadLibrary ("kernel32.dll"); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
254 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
255 gtzify_type p_gtzify = nullptr; |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
256 if (h_kernel32) |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
257 { |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
258 p_gtzify = reinterpret_cast<gtzify_type> |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
259 (GetProcAddress (h_kernel32, |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
260 "GetTimeZoneInformationForYear")); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
261 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
262 if (p_gtzify) |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
263 p_gtzify (m_year, nullptr, &tzi); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
264 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
265 FreeLibrary (h_kernel32); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
266 } |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
267 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
268 // Fall back to GetTimeZoneInformation, which might be wrong if a time |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
269 // zone switched the GMT offset. |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
270 if (! p_gtzify) |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
271 GetTimeZoneInformation (&tzi); |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
272 |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
273 if (m_isdst) |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
274 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
|
275 else |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
276 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
|
277 #endif |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
278 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
279 #if defined (HAVE_STRUCT_TM_TM_ZONE) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
280 if (t->tm_zone) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
281 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
|
282 #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
|
283 if (m_isdst) |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
284 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
|
285 else |
eacd1a3417c3
time: Get time zone offset on Windows (bug #53908).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27923
diff
changeset
|
286 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
|
287 #elif defined (HAVE_TZNAME) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
288 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
|
289 m_zone = tzname[t->tm_isdst]; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
290 #endif |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
291 } |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
292 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
293 void |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
294 localtime::init (const time& ot) |
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 m_usec = ot.usec (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
297 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
298 time_t t = ot.unix_time (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
299 |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21930
diff
changeset
|
300 base_tm::init (std::localtime (&t)); |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
301 } |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
302 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
303 void |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
304 gmtime::init (const time& ot) |
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 m_usec = ot.usec (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
307 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
308 time_t t = ot.unix_time (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
309 |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21930
diff
changeset
|
310 base_tm::init (std::gmtime (&t)); |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
311 } |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
312 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
313 void |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
314 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
|
315 { |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
316 struct ::tm t; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
317 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
318 t.tm_sec = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
319 t.tm_min = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
320 t.tm_hour = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
321 t.tm_mday = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
322 t.tm_mon = -1; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
323 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
|
324 t.tm_wday = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
325 t.tm_yday = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
326 t.tm_isdst = 0; |
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 defined (HAVE_TM_GMTOFF) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
329 t.tm_gmtoff = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
330 #endif |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
331 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
332 #if defined (HAVE_STRUCT_TM_TM_ZONE) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
333 char *ps = strsave (""); |
3709 | 334 t.tm_zone = ps; |
3253 | 335 #endif |
336 | |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
337 const char *p = str.c_str (); |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
338 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
339 char *q = octave_strptime_wrapper (p, fmt.c_str (), &t); |
3253 | 340 |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
341 // 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
|
342 // 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
|
343 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
|
344 && t.tm_year != std::numeric_limits<int>::min ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10279
diff
changeset
|
345 { |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
346 t.tm_isdst = -1; |
22062
d18aad835ad6
provide wrapper for gnulib mktime function
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
347 octave_mktime_wrapper (&t); |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
348 } |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
349 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
350 if (t.tm_mon < 0) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
351 t.tm_mon = 0; |
3253 | 352 |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
353 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
|
354 t.tm_year = 0; |
3253 | 355 |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
356 if (q) |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
357 nchars = q - p + 1; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
358 else |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
359 nchars = 0; |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
360 |
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
361 base_tm::init (&t); |
3253 | 362 |
3887 | 363 #if defined (HAVE_STRUCT_TM_TM_ZONE) |
3709 | 364 delete [] ps; |
3344 | 365 #endif |
3709 | 366 } |
21930
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
367 |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
368 void |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
369 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
|
370 { |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
371 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
|
372 } |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
373 |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
374 void |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
375 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
|
376 { |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
377 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
|
378 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
|
379 |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
380 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
|
381 &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
|
382 &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
|
383 &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
|
384 &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
|
385 &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
|
386 |
f0c5dd1ea2b9
hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
387 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
|
388 } |
21730
30c53770f47e
use namespace for system time classes
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
389 } |
3253 | 390 } |