30 const std::time_t minute = 60 ;
31 const std::time_t hour = 60 * minute ;
32 const std::time_t day = 24 * hour ;
37 us(static_cast<unsigned int>(us_))
39 if( us_ >= 1000000UL )
41 s +=
static_cast<std::time_t
>( us_ / 1000000UL ) ;
42 us =
static_cast<unsigned int>( us_ % 1000000UL ) ;
50 if( lhs.us > 1000000UL )
61 if( small_.us > big.us )
72 std::streamsize w = stream.width() ;
73 char c = stream.fill() ;
76 << std::setw(6) << std::setfill(
'0')
78 << std::setw(w) << std::setfill(c) ;
90 BrokenDownTime bdt( bdt_in ) ;
91 const bool leap_second = bdt.tm_sec == 60 ;
92 if( leap_second ) bdt.tm_sec = 59 ;
93 EpochTime tlocal( std::mktime(&bdt) , 0U ) ;
96 static std::time_t diff = 0 ;
97 static bool diff_set = false ;
101 if( equivalent( t , bdt_in ) )
102 return leap_second ? (t+1) : t ;
108 const std::time_t dt = minute * 30 ;
109 const std::time_t day_and_a_bit = day + dt ;
110 EpochTime t( tlocal.s - day_and_a_bit ) ;
111 const EpochTime end( tlocal.s + day_and_a_bit ) ;
112 for( diff = -day_and_a_bit ; t <= end ; t.s += dt , diff += dt )
114 if( equivalent( t , bdt_in ) )
117 return leap_second ? (t+1) : t ;
125 static BrokenDownTime zero ;
126 BrokenDownTime result = zero ;
127 G::DateTime::gmtime_imp( &epoch_time.s , &result ) ;
133 static BrokenDownTime zero ;
134 BrokenDownTime bdt_local = zero ;
135 G::DateTime::localtime_imp( &epoch_time.s , &bdt_local ) ;
141 BrokenDownTime bdt_local = local(utc) ;
144 bool ahead = local.s >= utc.s ;
145 EpochTime n( ahead ? (local.s-utc.s) : (utc.s-local.s) ) ;
146 return Offset( ahead , static_cast<unsigned int>(n.s) ) ;
151 std::ostringstream ss ;
152 ss << ( tz < 0 ?
"-" :
"+" ) ;
153 if( tz < 0 ) tz = -tz ;
154 ss << (tz/10) << (tz%10) <<
"00" ;
160 unsigned int hh = offset.second / 3600U ;
161 unsigned int mm = (offset.second / 60U) % 60 ;
163 std::ostringstream ss ;
164 char sign = (offset.first || (hh==0&&mm==0)) ?
'+' :
'-' ;
165 ss << sign << (hh/10U) << (hh%10U) << (mm/10) << (mm%10) ;
169 bool G::DateTime::equivalent(
EpochTime t ,
const BrokenDownTime & bdt_in )
171 BrokenDownTime bdt_test = utc(t) ;
172 return equivalent( bdt_test , bdt_in ) ;
175 bool G::DateTime::equivalent(
const BrokenDownTime & bdt1 ,
const BrokenDownTime & bdt2 )
178 bdt1.tm_mday == bdt2.tm_mday &&
179 bdt1.tm_hour == bdt2.tm_hour &&
180 bdt1.tm_min == bdt2.tm_min ;
static BrokenDownTime utc(EpochTime epoch_time)
Converts from epoch time to UTC broken-down-time.
A subsecond-resolution timestamp based on a time_t.
static Offset offset(EpochTime epoch_time)
Returns the offset between UTC and localtime as at 'epoch_time'.
static BrokenDownTime local(EpochTime epoch_time)
Converts from epoch time to local broken-down-time.
void streamOut(std::ostream &) const
Used by operator<<.
static std::string offsetString(Offset offset)
Converts the given utc/localtime offset into a five-character "+/-hhmm" string.
EpochTime(std::time_t)
Constructor.
static EpochTime epochTime(const BrokenDownTime &broken_down_time)
Converts from UTC broken-down-time to epoch time.