E-MailRelay
gdatetime.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gdatetime.cpp
19///
20
21#include "gdef.h"
22#include "gdatetime.h"
23#include "gstr.h"
24#include "gassert.h"
25#include <sstream>
26#include <iomanip>
27#include <utility>
28#include <vector>
29#include <type_traits>
30
31namespace G
32{
33 namespace DateTimeImp
34 {
35 static constexpr const char * good_format = "%ntYyCGgmUWVjdwuHIMSDFRT" ;
36 static constexpr unsigned int million = 1000000U ;
37
38 template <typename Tp> TimeInterval interval( Tp start , Tp end )
39 {
40 using namespace std::chrono ;
41 if( end <= start )
42 return TimeInterval::zero() ;
43 auto d = end - start ;
44
45 auto s = (duration_cast<seconds>(d)).count() ; G_ASSERT( s >= 0 ) ;
46 typename std::make_unsigned<decltype(s)>::type su = s ;
47 if( sizeof(su) > sizeof(TimeInterval::s_type) &&
48 su > std::numeric_limits<TimeInterval::s_type>::max() )
49 return TimeInterval::limit() ;
50
51 auto us = (duration_cast<microseconds>(d) % seconds(1)).count() ; G_ASSERT( us >= 0 ) ;
52 typename std::make_unsigned<decltype(us)>::type usu = us ;
53 G_ASSERT( us <= std::numeric_limits<TimeInterval::us_type>::max() ) ;
54
55 return TimeInterval( static_cast<TimeInterval::s_type>(su) , static_cast<TimeInterval::us_type>(usu) ) ;
56 }
57 }
58}
59
61 m_tm{}
62{
63 m_tm.tm_isdst = -1 ;
64}
65
66G::BrokenDownTime::BrokenDownTime( const struct std::tm & tm_in ) :
67 m_tm(tm_in)
68{
69 m_tm.tm_isdst = -1 ;
70 if( std::time_t(-1) == std::mktime( &m_tm ) ) // set wday and yday
71 throw DateTime::Error() ;
72}
73
75{
76 struct std::tm tm = m_tm ;
77 tm.tm_isdst = -1 ;
78 std::time_t t = std::mktime( &tm ) ;
79 if( t == std::time_t(-1) )
80 throw DateTime::Error() ;
81 return t ;
82}
83
85{
86 BrokenDownTime copy( *this ) ;
87 copy.m_tm.tm_sec = 0 ; // simplify for leap-seconds, add back below
88 return copy.epochTimeFromUtcImp() + m_tm.tm_sec ;
89}
90
91std::time_t G::BrokenDownTime::epochTimeFromUtcImp() const
92{
93 static bool diff_set = false ;
94 static std::time_t diff = 0 ;
95 return epochTimeFromUtcImp( diff_set , diff ) ;
96}
97
98std::time_t G::BrokenDownTime::epochTimeFromUtcImp( bool & diff_set , std::time_t & diff ) const
99{
100 constexpr int day = 24 * 60 * 60 ;
101 constexpr std::time_t dt = 60 * 15 ; // india 30mins, nepal 45mins // NOLINT
102 constexpr std::time_t day_and_a_bit = day + dt ;
103 constexpr std::time_t t_rounding = 30 ;
104
105 // use mktime() for a rough starting point
106 std::time_t t_base = epochTimeFromLocal() ;
107
108 // see if the previous diff result is still valid (no change of dst etc),
109 if( diff_set && !sameMinute( SystemTime(t_base+diff+t_rounding).utc() ) )
110 diff_set = false ;
111
112 // find the timezone diff
113 if( !diff_set )
114 {
115 // iterate over all possible timezones modifying the epoch time until
116 // its utc broken-down-time (gmtime()) matches ours
117 //
118 auto t = t_base - day_and_a_bit ;
119 auto end = t_base + day_and_a_bit ;
120 for( diff = -day_and_a_bit ; t <= end ; t += dt , diff += dt )
121 {
122 if( sameMinute( SystemTime(t+t_rounding).utc() ) )
123 {
124 diff_set = true ;
125 break ;
126 }
127 }
128 }
129
130 if( !diff_set )
131 throw DateTime::Error( "unsupported timezone" ) ;
132
133 return t_base + diff ;
134}
135
137{
138 BrokenDownTime tm ;
139 std::time_t s = t.s() ;
140 if( localtime_r( &s , &tm.m_tm ) == nullptr )
141 throw DateTime::Error() ;
142 return tm ;
143}
144
146{
147 BrokenDownTime tm ;
148 std::time_t s = t.s() ;
149 if( gmtime_r( &s , &tm.m_tm ) == nullptr )
150 throw DateTime::Error() ;
151 return tm ;
152}
153
154G::BrokenDownTime::BrokenDownTime( int y , int mon , int d , int h , int min , int sec ) :
155 m_tm{}
156{
157 m_tm.tm_year = y - 1900 ;
158 m_tm.tm_mon = mon - 1 ;
159 m_tm.tm_mday = d ;
160 m_tm.tm_hour = h ;
161 m_tm.tm_min = min ;
162 m_tm.tm_sec = sec ;
163 m_tm.tm_isdst = -1 ;
164 if( std::time_t(-1) == std::mktime( &m_tm ) ) // set wday and yday
165 throw DateTime::Error() ;
166}
167
168G::BrokenDownTime G::BrokenDownTime::midday( int year , int month , int day )
169{
170 return { year , month , day , 12 , 0 , 0 } ;
171}
172
173void G::BrokenDownTime::format( std::vector<char> & out , const char * fmt ) const
174{
175 for( const char * p = std::strchr(fmt,'%') ; p && p[1] ; p = std::strchr(p+1,'%') )
176 {
177 if( !std::strchr(DateTimeImp::good_format,p[1]) )
178 throw DateTime::Error() ;
179 }
180
181 if( std::strftime( &out[0] , out.size() , fmt , &m_tm ) == 0U )
182 throw DateTime::Error() ;
183}
184
185std::string G::BrokenDownTime::str() const
186{
187 return str( "%F %T" ) ;
188}
189
190std::string G::BrokenDownTime::str( const char * fmt ) const
191{
192 std::size_t n = std::strlen( fmt ) ;
193 for( const char * p = std::strchr(fmt,'%') ; p && p[1] ; p = std::strchr(p+1,'%') )
194 n += 10U ; // biggest allowed format is eg. %F -> "2001-12-31"
195
196 std::vector<char> buffer( n ) ;
197 format( buffer , fmt ) ;
198 buffer.at(buffer.size()-1U) = '\0' ; // just in case
199 return std::string( &buffer[0] ) ;
200}
201
203{
204 return m_tm.tm_hour ;
205}
206
208{
209 return m_tm.tm_min ;
210}
211
213{
214 return m_tm.tm_sec ;
215}
216
218{
219 return m_tm.tm_year + 1900 ;
220}
221
223{
224 return m_tm.tm_mon + 1 ;
225}
226
228{
229 return m_tm.tm_mday ;
230}
231
233{
234 return m_tm.tm_wday ;
235}
236
238{
239 return
240 year() == other.year() &&
241 month() == other.month() &&
242 day() == other.day() &&
243 hour() == other.hour() &&
244 min() == other.min() ;
245}
246
247// ==
248
249G::SystemTime::SystemTime( time_point_type tp ) :
250 m_tp(tp)
251{
252}
253
254G::SystemTime::SystemTime( std::time_t t , unsigned long us ) noexcept
255{
256 m_tp = std::chrono::system_clock::from_time_t(t) ;
257 m_tp += std::chrono::microseconds( us ) ;
258}
259
261{
262 return SystemTime( std::chrono::system_clock::now() ) ;
263}
264
266{
267 return start.interval( *this ) ;
268}
269
271{
272 return DateTimeImp::interval( m_tp , end.m_tp ) ;
273}
274
275G::SystemTime & G::SystemTime::add( unsigned long us )
276{
277 m_tp += std::chrono::microseconds( us ) ;
278 return *this ;
279}
280
281bool G::SystemTime::sameSecond( const SystemTime & t ) const noexcept
282{
283 return s() == t.s() ;
284}
285
287{
288 return BrokenDownTime::local( *this ) ;
289}
290
292{
293 return BrokenDownTime::utc( *this ) ;
294}
295
296unsigned int G::SystemTime::ms() const
297{
298 using namespace std::chrono ;
299 return static_cast<unsigned int>((duration_cast<milliseconds>(m_tp.time_since_epoch()) % seconds(1)).count()) ;
300}
301
302unsigned int G::SystemTime::us() const
303{
304 using namespace std::chrono ;
305 return static_cast<unsigned int>((duration_cast<microseconds>(m_tp.time_since_epoch()) % seconds(1)).count()) ;
306}
307
308std::time_t G::SystemTime::s() const noexcept
309{
310 using namespace std::chrono ;
311 G_ASSERT( duration_cast<seconds>(m_tp.time_since_epoch()).count() == system_clock::to_time_t(m_tp) ) ; // as per c++17
312 return system_clock::to_time_t( m_tp ) ;
313}
314
316{
317 duration_type zero{0} ;
318 G_ASSERT( SystemTime(time_point_type(zero)).s() == 0 ) ; // assert 1970 epoch as per c++17
319 return SystemTime( time_point_type(zero) ) ;
320}
321
322bool G::SystemTime::operator<( const SystemTime & other ) const
323{
324 return m_tp < other.m_tp ;
325}
326
327bool G::SystemTime::operator<=( const SystemTime & other ) const
328{
329 return m_tp <= other.m_tp ;
330}
331
332bool G::SystemTime::operator==( const SystemTime & other ) const
333{
334 return m_tp == other.m_tp ;
335}
336
337bool G::SystemTime::operator!=( const SystemTime & other ) const
338{
339 return !( *this == other ) ;
340}
341
342bool G::SystemTime::operator>( const SystemTime & other ) const
343{
344 return m_tp > other.m_tp ;
345}
346
347bool G::SystemTime::operator>=( const SystemTime & other ) const
348{
349 return m_tp >= other.m_tp ;
350}
351
353{
354 SystemTime t( *this ) ;
355 t += interval ;
356 return t ;
357}
358
360{
361 using namespace std::chrono ;
362 m_tp += seconds(i.s()) ;
363 m_tp += microseconds(i.us()) ;
364}
365
366void G::SystemTime::streamOut( std::ostream & stream ) const
367{
368 int w = static_cast<int>( stream.width() ) ;
369 char c = stream.fill() ;
370 stream
371 << s() << "."
372 << std::setw(6) << std::setfill('0')
373 << us()
374 << std::setw(w) << std::setfill(c) ;
375}
376
377std::ostream & G::operator<<( std::ostream & stream , const SystemTime & t )
378{
379 t.streamOut( stream ) ;
380 return stream ;
381}
382
383// ==
384
386{
387 return TimerTime( std::chrono::steady_clock::now() , false ) ;
388}
389
391{
392 duration_type zero_duration{0} ;
393 return TimerTime( time_point_type(zero_duration) , true ) ;
394}
395
396G::TimerTime G::TimerTime::test( int s , int us )
397{
398 return TimerTime( time_point_type(std::chrono::seconds(s)+std::chrono::microseconds(us)) , s==0 && us==0 ) ;
399}
400
401G::TimerTime::TimerTime( time_point_type tp , bool is_zero ) :
402 m_is_zero(is_zero) ,
403 m_tp(tp)
404{
405}
406
407unsigned long G::TimerTime::test_s() const
408{
409 using namespace std::chrono ;
410 return static_cast<unsigned long>(duration_cast<seconds>(m_tp.time_since_epoch()).count()) ;
411}
412
413unsigned long G::TimerTime::test_us() const
414{
415 using namespace std::chrono ;
416 return static_cast<unsigned long>((duration_cast<microseconds>(m_tp.time_since_epoch()) % seconds(1)).count()) ;
417}
418
420{
421 TimerTime t( *this ) ;
422 t += interval ;
423 t.m_is_zero = m_is_zero && interval.s() == 0U && interval.us() == 0U ;
424 return t ;
425}
426
428{
429 using namespace std::chrono ;
430 m_tp += seconds(i.s()) ;
431 m_tp += microseconds(i.us()) ;
432 m_is_zero = m_is_zero && i.s() == 0U && i.us() == 0U ;
433}
434
436{
437 return start.interval( *this ) ;
438}
439
441{
442 return DateTimeImp::interval( m_tp , end.m_tp ) ;
443}
444
445bool G::TimerTime::sameSecond( const TimerTime & t ) const
446{
447 using namespace std::chrono ;
448 return
449 duration_cast<seconds>(m_tp.time_since_epoch()) ==
450 duration_cast<seconds>(t.m_tp.time_since_epoch()) ;
451}
452
453bool G::TimerTime::operator<( const TimerTime & other ) const
454{
455 return m_tp < other.m_tp ;
456}
457
458bool G::TimerTime::operator<=( const TimerTime & other ) const
459{
460 return m_tp <= other.m_tp ;
461}
462
463bool G::TimerTime::operator==( const TimerTime & other ) const
464{
465 return m_tp == other.m_tp ;
466}
467
468bool G::TimerTime::operator!=( const TimerTime & other ) const
469{
470 return m_tp != other.m_tp ;
471}
472
473bool G::TimerTime::operator>( const TimerTime & other ) const
474{
475 return m_tp > other.m_tp ;
476}
477
478bool G::TimerTime::operator>=( const TimerTime & other ) const
479{
480 return m_tp >= other.m_tp ;
481}
482
483// ==
484
485G::TimeInterval::TimeInterval( s_type s , us_type us ) :
486 m_s(s) ,
487 m_us(us)
488{
489 normalise() ;
490}
491
493 m_s(0) ,
494 m_us(0)
495{
496 TimeInterval i = start.interval( end ) ;
497 m_s = i.m_s ;
498 m_us = i.m_us ;
499 normalise() ;
500}
501
502G::TimeInterval::TimeInterval( const TimerTime & start , const TimerTime & end ) :
503 m_s(0) ,
504 m_us(0)
505{
506 TimeInterval i = start.interval( end ) ;
507 m_s = i.m_s ;
508 m_us = i.m_us ;
509 normalise() ;
510}
511
512void G::TimeInterval::normalise()
513{
514 using namespace G::DateTimeImp ;
515 if( m_us >= million )
516 {
517 m_us -= million ;
518 increase( m_s ) ;
519 if( m_us >= million ) // still
520 {
521 increase( m_s , m_us / million ) ;
522 m_us = m_us % million ;
523 }
524 }
525}
526
528{
529 using namespace G::DateTimeImp ;
530 return TimeInterval( std::numeric_limits<s_type>::max() , million-1U ) ;
531}
532
534{
535 return TimeInterval( 0UL , 0U ) ;
536}
537
538G::TimeInterval::s_type G::TimeInterval::s() const
539{
540 return m_s ;
541}
542
543G::TimeInterval::us_type G::TimeInterval::us() const
544{
545 return m_us ;
546}
547
548bool G::TimeInterval::operator==( const TimeInterval & other ) const
549{
550 return m_s == other.m_s && m_us == other.m_us ;
551}
552
553bool G::TimeInterval::operator!=( const TimeInterval & other ) const
554{
555 return !( *this == other ) ;
556}
557
558bool G::TimeInterval::operator<( const TimeInterval & other ) const
559{
560 return m_s < other.m_s || ( m_s == other.m_s && m_us < other.m_us ) ;
561}
562
563bool G::TimeInterval::operator<=( const TimeInterval & other ) const
564{
565 return *this == other || *this < other ;
566}
567
568bool G::TimeInterval::operator>( const TimeInterval & other ) const
569{
570 return m_s > other.m_s || ( m_s == other.m_s && m_us > other.m_us ) ;
571}
572
573bool G::TimeInterval::operator>=( const TimeInterval & other ) const
574{
575 return *this == other || *this > other ;
576}
577
579{
580 TimeInterval t( *this ) ;
581 t += other ;
582 return t ;
583}
584
586{
587 TimeInterval t( *this ) ;
588 t -= other ;
589 return t ;
590}
591
592void G::TimeInterval::increase( unsigned int & s , unsigned int ds )
593{
594 const auto old = s ;
595 s += ds ;
596 const bool overflow = s < old ;
597 if( overflow )
598 throw DateTime::Error( "overflow" ) ;
599}
600
602{
603 using namespace G::DateTimeImp ;
604 m_us += i.m_us ;
605 if( m_us >= million )
606 {
607 m_us -= million ;
608 increase( m_s ) ;
609 }
610 increase( m_s , i.m_s ) ;
611}
612
613void G::TimeInterval::decrease( unsigned int & s , unsigned int ds )
614{
615 if( s < ds )
616 throw DateTime::Error( "underflow" ) ;
617 s -= ds ;
618}
619
621{
622 using namespace G::DateTimeImp ;
623 if( m_us < i.m_us )
624 {
625 decrease( m_s ) ;
626 m_us += million ;
627 }
628 m_us -= i.m_us ;
629 decrease( m_s , i.m_s ) ;
630}
631
632void G::TimeInterval::streamOut( std::ostream & stream ) const
633{
634 int w = static_cast<int>( stream.width() ) ;
635 char c = stream.fill() ;
636 stream
637 << s() << "."
638 << std::setw(6) << std::setfill('0')
639 << us()
640 << std::setw(w) << std::setfill(c) ;
641}
642
643std::ostream & G::operator<<( std::ostream & stream , const TimeInterval & ti )
644{
645 ti.streamOut( stream ) ;
646 return stream ;
647}
648
649// ==
650
651G::DateTime::Offset G::DateTime::offset( SystemTime t_in )
652{
653 G_ASSERT( !(t_in == SystemTime::zero()) ) ;
654 SystemTime t_zone( BrokenDownTime::local(t_in).epochTimeFromUtc() ) ;
655 bool ahead = t_in < t_zone ; // ie. east-of
656 TimeInterval i = ahead ? (t_zone-t_in) : (t_in-t_zone) ;
657 return Offset{ ahead , i.s() } ;
658}
659
660std::string G::DateTime::offsetString( int tz )
661{
662 std::ostringstream ss ;
663 ss << ( tz < 0 ? "-" : "+" ) ;
664 if( tz < 0 ) tz = -tz ;
665 ss << (tz/10) << (tz%10) << "00" ;
666 return ss.str() ;
667}
668
669std::string G::DateTime::offsetString( Offset offset )
670{
671 unsigned int hh = (offset.second+30U) / 3600U ;
672 unsigned int mm = ((offset.second+30U) / 60U) % 60 ;
673
674 std::ostringstream ss ;
675 char sign = (offset.first || (hh==0&&mm==0)) ? '+' : '-' ;
676 ss << sign << (hh/10U) << (hh%10U) << (mm/10) << (mm%10) ;
677 return ss.str() ;
678}
679
An encapsulation of 'struct std::tm'.
Definition: gdatetime.h:45
int wday() const
Returns week day where sunday=0 and saturday=6.
Definition: gdatetime.cpp:232
int day() const
Returns the 1..31 month-day value.
Definition: gdatetime.cpp:227
std::time_t epochTimeFromLocal() const
Uses std::mktime() to convert this locale-dependent local broken-down time into epoch time.
Definition: gdatetime.cpp:74
bool sameMinute(const BrokenDownTime &other) const
Returns true if this and the other broken-down times are the same, at minute resolution with no round...
Definition: gdatetime.cpp:237
std::string str() const
Returns str() using a "%F %T" format.
Definition: gdatetime.cpp:185
BrokenDownTime(const struct std::tm &)
Constructor.
Definition: gdatetime.cpp:66
int sec() const
Returns the 0..59 or 0..60 seconds value.
Definition: gdatetime.cpp:212
static BrokenDownTime utc(SystemTime)
Factory function for the utc time of the given epoch time.
Definition: gdatetime.cpp:145
static BrokenDownTime midday(int year, int month, int day)
Factory function for midday on the given date.
Definition: gdatetime.cpp:168
int month() const
Returns the 1..12 month value.
Definition: gdatetime.cpp:222
void format(std::vector< char > &out, const char *fmt) const
Puts the formatted date, including a terminating null character, into the given buffer.
Definition: gdatetime.cpp:173
static BrokenDownTime local(SystemTime)
Factory function for the locale-dependent local time of the given epoch time.
Definition: gdatetime.cpp:136
int hour() const
Returns the 0..23 hour value.
Definition: gdatetime.cpp:202
int year() const
Returns the four-digit year value.
Definition: gdatetime.cpp:217
std::time_t epochTimeFromUtc() const
Searches std::mktime() over the range of all timezones to convert this utc broken-down time into epoc...
Definition: gdatetime.cpp:84
int min() const
Returns the 0..59 minute value.
Definition: gdatetime.cpp:207
static Offset offset(SystemTime)
Returns the offset in seconds between UTC and localtime as at the given system time.
Definition: gdatetime.cpp:651
static std::string offsetString(Offset offset)
Converts the given utc/localtime offset into a five-character "+/-hhmm" string.
Definition: gdatetime.cpp:669
Represents a unix-epoch time with microsecond resolution.
Definition: gdatetime.h:125
TimeInterval operator-(const SystemTime &start) const
Returns the given start time's interval() compared to this end time.
Definition: gdatetime.cpp:265
static SystemTime now()
Factory function for the current time.
Definition: gdatetime.cpp:260
std::time_t s() const noexcept
Returns the number of seconds since the start of the epoch.
Definition: gdatetime.cpp:308
SystemTime operator+(TimeInterval) const
Returns this time with given interval added.
Definition: gdatetime.cpp:352
unsigned int ms() const
Returns the millisecond fraction.
Definition: gdatetime.cpp:296
unsigned int us() const
Returns the microsecond fraction.
Definition: gdatetime.cpp:302
bool operator!=(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:337
BrokenDownTime local() const
Returns the locale-dependent local broken-down time.
Definition: gdatetime.cpp:286
bool operator>(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:342
void streamOut(std::ostream &) const
Streams out the time comprised of the s() value, a decimal point, and then the six-digit us() value.
Definition: gdatetime.cpp:366
TimeInterval interval(const SystemTime &end) const
Returns the interval between this time and the given end time.
Definition: gdatetime.cpp:270
bool sameSecond(const SystemTime &other) const noexcept
Returns true if this time and the other time are the same, at second resolution.
Definition: gdatetime.cpp:281
bool operator<=(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:327
bool operator>=(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:347
static SystemTime zero()
Factory function for the start of the epoch.
Definition: gdatetime.cpp:315
SystemTime(std::time_t, unsigned long us=0UL) noexcept
Constructor.
Definition: gdatetime.cpp:254
BrokenDownTime utc() const
Returns the utc broken-down time.
Definition: gdatetime.cpp:291
void operator+=(TimeInterval)
Adds the given interval. Throws on overflow.
Definition: gdatetime.cpp:359
bool operator<(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:322
bool operator==(const SystemTime &) const
Comparison operator.
Definition: gdatetime.cpp:332
An interval between two G::SystemTime values or two G::TimerTime values.
Definition: gdatetime.h:289
TimeInterval(unsigned int s, unsigned int us=0U)
Constructor.
Definition: gdatetime.cpp:485
TimeInterval operator+(const TimeInterval &) const
Returns the combined interval. Throws on overflow.
Definition: gdatetime.cpp:578
static TimeInterval zero()
Factory function for the zero interval.
Definition: gdatetime.cpp:533
void operator-=(TimeInterval)
Subtracts the given interval. Throws on underflow.
Definition: gdatetime.cpp:620
bool operator==(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:548
static TimeInterval limit()
Factory function for the maximum valid interval.
Definition: gdatetime.cpp:527
unsigned int s() const
Returns the number of seconds.
Definition: gdatetime.cpp:538
unsigned int us() const
Returns the fractional microseconds part.
Definition: gdatetime.cpp:543
void operator+=(TimeInterval)
Adds the given interval. Throws on overflow.
Definition: gdatetime.cpp:601
bool operator>(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:568
TimeInterval operator-(const TimeInterval &) const
Returns the interval difference. Throws on underflow.
Definition: gdatetime.cpp:585
bool operator<(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:558
bool operator!=(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:553
void streamOut(std::ostream &) const
Streams out the interval.
Definition: gdatetime.cpp:632
bool operator>=(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:573
bool operator<=(const TimeInterval &) const
Comparison operator.
Definition: gdatetime.cpp:563
A monotonically increasing subsecond-resolution timestamp, notionally unrelated to time_t.
Definition: gdatetime.h:213
static TimerTime now()
Factory function for the current steady-clock time.
Definition: gdatetime.cpp:385
TimerTime operator+(const TimeInterval &) const
Returns this time with given interval added.
Definition: gdatetime.cpp:419
bool operator>(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:473
TimeInterval interval(const TimerTime &end) const
Returns the interval between this time and the given end time.
Definition: gdatetime.cpp:440
bool operator==(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:463
bool operator!=(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:468
TimeInterval operator-(const TimerTime &start) const
Returns the given start time's interval() compared to this end time.
Definition: gdatetime.cpp:435
bool sameSecond(const TimerTime &other) const
Returns true if this time and the other time are the same, at second resolution.
Definition: gdatetime.cpp:445
void operator+=(TimeInterval)
Adds an interval.
Definition: gdatetime.cpp:427
static TimerTime zero()
Factory function for the start of the epoch.
Definition: gdatetime.cpp:390
bool operator<(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:453
bool operator<=(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:458
bool operator>=(const TimerTime &) const
Comparison operator.
Definition: gdatetime.cpp:478
A simple version of boost::format for formatting strings in an i18n-friendly way.
Definition: gformat.h:46
Low-level classes.
Definition: galign.h:28