Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 11073
Merged at revision: 11238
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 243 lines (+43/-55)
5 files modified
src/context/dynamic_context.cpp (+21/-39)
src/runtime/datetime/datetime_impl.cpp (+4/-4)
src/util/indent.h (+1/-1)
src/util/time_util.cpp (+12/-8)
src/util/time_util.h (+5/-3)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+148075@code.launchpad.net

Commit message

Time code clean-up.

Description of the change

Time code clean-up.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-02-13T02-54-50.012Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve.

lp:~paul-lucas/zorba/pjl-misc updated
11072. By Paul J. Lucas

Merge from trunk.

11073. By Paul J. Lucas

s/int/long/

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2013-02-13T04-22-51.065Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/context/dynamic_context.cpp'
2--- src/context/dynamic_context.cpp 2013-01-08 08:34:08 +0000
3+++ src/context/dynamic_context.cpp 2013-02-13 03:26:23 +0000
4@@ -15,18 +15,9 @@
5 */
6 #include "stdafx.h"
7
8-#ifdef WIN32
9-#include <sys/types.h>
10-#include <sys/timeb.h>
11-#endif
12+#include <assert.h>
13+
14 #include "common/common.h"
15-#include <assert.h>
16-#include <time.h>
17-#include <sys/timeb.h>
18-#ifdef UNIX
19-#include <sys/time.h>
20-#include <unistd.h>
21-#endif
22 #include "store/api/iterator.h"
23 #include "store/api/temp_seq.h"
24 #include "store/api/item_factory.h"
25@@ -52,6 +43,7 @@
26
27 #include "zorbautils/hashmap_itemp.h"
28 #include "util/string_util.h"
29+#include "util/time_util.h"
30
31 #include "diagnostics/assert.h"
32 #include "diagnostics/util_macros.h"
33@@ -235,34 +227,24 @@
34 ********************************************************************************/
35 void dynamic_context::reset_current_date_time()
36 {
37- int lTimeShift = 0;
38-#if defined (WIN32)
39- struct _timeb timebuffer;
40- _ftime_s( &timebuffer );
41- struct ::tm gmtm;
42- localtime_s(&gmtm, &timebuffer.time); //thread safe localtime on Windows
43- lTimeShift = -timebuffer.timezone*60;
44- if (gmtm.tm_isdst != 0)
45- lTimeShift += 3600;
46-#else
47- struct timeb timebuffer;
48- ftime( &timebuffer );
49- struct ::tm gmtm;
50- localtime_r(&timebuffer.time, &gmtm); //thread safe localtime on Linux
51- lTimeShift = gmtm.tm_gmtoff;
52-#endif
53-
54- set_implicit_timezone(lTimeShift);//in seconds
55-
56- GENV_ITEMFACTORY->createDateTime(theCurrentDateTime,
57- static_cast<short>(gmtm.tm_year + 1900),
58- static_cast<short>(gmtm.tm_mon + 1),
59- static_cast<short>(gmtm.tm_mday),
60- static_cast<short>(gmtm.tm_hour),
61- static_cast<short>(gmtm.tm_min),
62- gmtm.tm_sec + timebuffer.millitm/1000.0,
63- static_cast<short>(theTimezone/3600));
64-
65+ time::sec_type sec;
66+ time::usec_type usec;
67+ time::get_epoch( &sec, &usec );
68+ time::ztm tm;
69+ time::get_localtime( &tm, sec );
70+
71+ set_implicit_timezone( tm.ZTM_GMTOFF );
72+
73+ GENV_ITEMFACTORY->createDateTime(
74+ theCurrentDateTime,
75+ static_cast<short>( tm.tm_year + TM_YEAR_BASE ),
76+ static_cast<short>( tm.tm_mon + 1 ),
77+ static_cast<short>( tm.tm_mday ),
78+ static_cast<short>( tm.tm_hour ),
79+ static_cast<short>( tm.tm_min ),
80+ tm.tm_sec + usec / 1000000.0,
81+ static_cast<short>( tm.ZTM_GMTOFF / 3600 )
82+ );
83 }
84
85
86
87=== modified file 'src/runtime/datetime/datetime_impl.cpp'
88--- src/runtime/datetime/datetime_impl.cpp 2013-01-29 06:10:09 +0000
89+++ src/runtime/datetime/datetime_impl.cpp 2013-02-13 03:26:23 +0000
90@@ -175,7 +175,7 @@
91
92 bool CurrentDateTime::nextImpl( store::Item_t& result,
93 PlanState &plan_state ) const {
94- time_t sec;
95+ time::sec_type sec;
96 time::usec_type usec;
97 time::get_epoch( &sec, &usec );
98 time::ztm tm;
99@@ -201,7 +201,7 @@
100
101 bool CurrentTime::nextImpl( store::Item_t& result,
102 PlanState &plan_state ) const {
103- time_t sec;
104+ time::sec_type sec;
105 time::usec_type usec;
106 time::get_epoch( &sec, &usec );
107 time::ztm tm;
108@@ -234,7 +234,7 @@
109 consumeNext( item, theChildren[0], plan_state );
110 millis = item->getLongValue();
111
112- time::get_gmtime( &tm, static_cast<time_t>( millis / 1000 ) );
113+ time::get_gmtime( &tm, static_cast<time::sec_type>( millis / 1000 ) );
114 GENV_ITEMFACTORY->createDateTime(
115 result,
116 static_cast<short>( tm.tm_year + TM_YEAR_BASE ),
117@@ -360,7 +360,7 @@
118
119 bool Timestamp::nextImpl( store::Item_t& result,
120 PlanState &plan_state ) const {
121- time_t sec;
122+ time::sec_type sec;
123 time::get_epoch( &sec );
124
125 PlanIteratorState *state;
126
127=== modified file 'src/util/indent.h'
128--- src/util/indent.h 2013-02-12 03:55:18 +0000
129+++ src/util/indent.h 2013-02-13 03:26:23 +0000
130@@ -81,7 +81,7 @@
131 std::basic_ostream<charT,Traits>&
132 indent( std::basic_ostream<charT,Traits> &os )
133 {
134- for ( int i = get_indent( os ); i > 0; --i )
135+ for ( long i = get_indent( os ); i > 0; --i )
136 os << ' ';
137 return os;
138 }
139
140=== modified file 'src/util/time_util.cpp'
141--- src/util/time_util.cpp 2013-01-10 01:23:21 +0000
142+++ src/util/time_util.cpp 2013-02-13 03:26:23 +0000
143@@ -144,14 +144,14 @@
144 return days[ mon ] + (mon == 1 /* Feb */ && is_leap_year( year ));
145 }
146
147-void get_epoch( time_t *sec, usec_type *usec ) {
148+void get_epoch( sec_type *sec, usec_type *usec ) {
149 #ifdef WIN32
150 FILETIME ft;
151 ::GetSystemTimeAsFileTime( &ft );
152 unsigned __int64 temp = ((__int64)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
153 temp /= 10; // nanosec -> usec
154 temp -= DELTA_EPOCH_IN_USEC; // 1601 -> 1970
155- *sec = (time_t)(temp / 1000000UL); // usec -> sec
156+ *sec = (sec_type)(temp / 1000000UL); // usec -> sec
157 if ( usec )
158 *usec = (usec_type)(temp % 1000000UL);
159 #else
160@@ -163,18 +163,18 @@
161 #endif /* WIN32 */
162 }
163
164-void get_gmtime( ztm *tm, time_t when ) {
165+void get_gmtime( ztm *tm, sec_type when ) {
166 if ( !when )
167 get_epoch( &when );
168 #ifdef WIN32
169 ::gmtime_s( tm, &when );
170+#else
171+ ::gmtime_r( &when, tm );
172+#endif /* WIN32 */
173 tm->ZTM_GMTOFF = 0;
174-#else
175- ::gmtime_r( &when, tm );
176-#endif /* WIN32 */
177 }
178
179-void get_localtime( ztm *tm, time_t when ) {
180+void get_localtime( ztm *tm, sec_type when ) {
181 if ( !when )
182 get_epoch( &when );
183 #ifdef WIN32
184@@ -182,6 +182,10 @@
185 tm->ZTM_GMTOFF = - _timezone; // seconds west -> east
186 #else
187 ::localtime_r( &when, tm );
188+#if !defined(ZORBA_HAVE_STRUCT_TM_TM_GMTOFF) && \
189+ !defined(ZORBA_HAVE_STRUCT_TM___TM_GMTOFF)
190+ tm->ZTM_GMTOFF = ::timegm( tm ) - when;
191+#endif
192 #endif /* WIN32 */
193 }
194
195@@ -191,7 +195,7 @@
196 ::GetTimeZoneInformation( &tz );
197 return tz.Bias * -60; // minutes west -> seconds east
198 #else
199- time_t const now = ::time( nullptr );
200+ sec_type const now = ::time( nullptr );
201 ztm tm;
202 ::localtime_r( &now, &tm );
203 return ::timegm( &tm ) - now;
204
205=== modified file 'src/util/time_util.h'
206--- src/util/time_util.h 2012-12-29 17:08:29 +0000
207+++ src/util/time_util.h 2013-02-13 03:26:23 +0000
208@@ -36,6 +36,8 @@
209
210 ///////////////////////////////////////////////////////////////////////////////
211
212+typedef time_t sec_type;
213+
214 #ifdef WIN32
215 typedef unsigned long usec_type;
216 #else
217@@ -119,7 +121,7 @@
218 * @param usec A pointer to the result in microseconds or \c null if this is
219 * not desired.
220 */
221-void get_epoch( time_t *sec, usec_type *usec = nullptr );
222+void get_epoch( sec_type *sec, usec_type *usec = nullptr );
223
224 /**
225 * Gets the Greenwich time and populates the given ztm structure.
226@@ -128,7 +130,7 @@
227 * @param when If &gt; 0, populates \a tm based on \a when number of seconds
228 * since \e epoch; if 0, populates \a when based on \e now.
229 */
230-void get_gmtime( ztm *tm, time_t when = 0 );
231+void get_gmtime( ztm *tm, sec_type when = 0 );
232
233 /**
234 * Gets the offset of the current timezone from Greenwich time.
235@@ -145,7 +147,7 @@
236 * @param when If &gt; 0, populates \a tm based on \a when number of seconds
237 * since \e epoch; if 0, populates \a when based on \e now.
238 */
239-void get_localtime( ztm *tm, time_t when = 0 );
240+void get_localtime( ztm *tm, sec_type when = 0 );
241
242 /**
243 * Checks whether the given year is a leap year.

Subscribers

People subscribed via source and target branches