37 class BrokenDownTime ;
71 bool format(
char * out , std::size_t out_size ,
const char * fmt )
const ;
78 void format( std::vector<char> & out ,
const char * fmt )
const ;
82 std::string
str(
const char * fmt )
const ;
86 std::string
str()
const ;
132 friend class G::DateTimeTest ;
133 struct std::tm m_tm {} ;
148 explicit SystemTime( std::time_t ,
unsigned long us = 0UL ) noexcept ;
166 unsigned int ms()
const ;
169 unsigned int us()
const ;
172 std::time_t
s()
const noexcept ;
216 friend class G::DateTimeTest ;
217 using time_point_type = std::chrono::time_point<std::chrono::system_clock> ;
218 using duration_type = time_point_type::duration ;
223 time_point_type m_tp ;
233 using time_point_type = std::chrono::time_point<std::chrono::steady_clock> ;
242 bool isZero()
const noexcept ;
249 static constexpr bool less_noexcept =
noexcept(time_point_type() < time_point_type()) ;
288 friend class G::DateTimeTest ;
289 using duration_type = time_point_type::duration ;
292 unsigned long s()
const ;
293 unsigned long us()
const ;
294 std::string str()
const ;
297 time_point_type m_tp ;
307 using s_type =
unsigned int ;
308 using us_type =
unsigned int ;
327 unsigned int s()
const ;
330 unsigned int us()
const ;
368 static void increase(
unsigned int &
s ,
unsigned int ds = 1U ) ;
369 static void decrease(
unsigned int &
s ,
unsigned int ds = 1U ) ;
382 G_EXCEPTION_CLASS( Error ,
tx(
"date/time error") )
383 using Offset = std::pair<bool,unsigned int> ;
404 std::ostream & operator<<( std::ostream & ,
const SystemTime & ) ;
405 std::ostream & operator<<( std::ostream & ,
const TimeInterval & ) ;
406 inline bool operator<(
const TimerTime & a ,
const TimerTime & b )
noexcept(TimerTime::less_noexcept)
414 return a.m_tp < b.m_tp ;
419 return sameMinute(other) && m_tm.tm_sec == other.m_tm.tm_sec ;
424 return !sameMinute(other) || m_tm.tm_sec != other.m_tm.tm_sec ;
An encapsulation of 'struct std::tm'.
int wday() const
Returns week day where sunday=0 and saturday=6.
bool operator!=(const BrokenDownTime &) const noexcept
Inequality test.
int day() const
Returns the 1..31 month-day value.
static BrokenDownTime null()
Factory function for an unusable object with bogus component values.
std::time_t epochTimeFromLocal() const
Uses std::mktime() to convert this locale-dependent local broken-down time into epoch time.
std::string str() const
Returns str() using a "%F %T" format.
int sec() const
Returns the 0..59 or 0..60 seconds value.
static BrokenDownTime utc(SystemTime)
Factory function for the utc broken-down time of the given epoch time.
bool operator==(const BrokenDownTime &) const noexcept
Equality test.
static BrokenDownTime midday(int year, int month, int day)
Factory function for midday on the given date.
static BrokenDownTime midnight(int year, int month, int day)
Factory function for midnight starting the given date.
int month() const
Returns the 1..12 month value.
static BrokenDownTime local(SystemTime)
Factory function for the locale-dependent local broken-down time of the given epoch time.
int hour() const
Returns the 0..23 hour value.
int year() const
Returns the four-digit year value.
bool format(char *out, std::size_t out_size, const char *fmt) const
Puts the formatted date, including a terminating null character, into the given output buffer.
bool sameMinute(const BrokenDownTime &) const noexcept
Returns true if this and the other broken-down times are the same, at minute resolution with no round...
std::time_t epochTimeFromUtc() const
Converts this utc broken-down time into epoch time.
int min() const
Returns the 0..59 minute value.
A static class that knows about timezone offsets.
static Offset offset(SystemTime)
Returns the offset in seconds between UTC and localtime as at the given system time.
static std::string offsetString(Offset offset)
Converts the given utc/localtime offset into a five-character "+/-hhmm" string.
Represents a unix-epoch time with microsecond resolution.
TimeInterval operator-(const SystemTime &start) const
Returns the given start time's interval() compared to this end time.
static SystemTime now()
Factory function for the current time.
std::time_t s() const noexcept
Returns the number of seconds since the start of the epoch.
SystemTime operator+(TimeInterval) const
Returns this time with given interval added.
unsigned int ms() const
Returns the millisecond fraction.
unsigned int us() const
Returns the microsecond fraction.
bool operator!=(const SystemTime &) const
Comparison operator.
BrokenDownTime local() const
Returns the locale-dependent local broken-down time.
bool operator>(const SystemTime &) const
Comparison operator.
void streamOut(std::ostream &) const
Streams out the time comprised of the s() value, a decimal point, and then the six-digit us() value.
TimeInterval interval(const SystemTime &end) const
Returns the interval between this time and the given end time.
bool sameSecond(const SystemTime &other) const noexcept
Returns true if this time and the other time are the same, at second resolution.
bool operator<=(const SystemTime &) const
Comparison operator.
bool isZero() const
Returns true if zero().
bool operator>=(const SystemTime &) const
Comparison operator.
static SystemTime zero()
Factory function for the start of the epoch.
SystemTime(std::time_t, unsigned long us=0UL) noexcept
Constructor.
BrokenDownTime utc() const
Returns the utc broken-down time.
void operator+=(TimeInterval)
Adds the given interval. Throws on overflow.
bool operator<(const SystemTime &) const
Comparison operator.
bool operator==(const SystemTime &) const
Comparison operator.
An interval between two G::SystemTime values or two G::TimerTime values.
TimeInterval(unsigned int s, unsigned int us=0U)
Constructor.
TimeInterval operator+(const TimeInterval &) const
Returns the combined interval. Throws on overflow.
static TimeInterval zero()
Factory function for the zero interval.
void operator-=(TimeInterval)
Subtracts the given interval. Throws on underflow.
bool operator==(const TimeInterval &) const
Comparison operator.
static TimeInterval limit()
Factory function for the maximum valid interval.
unsigned int s() const
Returns the number of seconds.
unsigned int us() const
Returns the fractional microseconds part.
void operator+=(TimeInterval)
Adds the given interval. Throws on overflow.
bool operator>(const TimeInterval &) const
Comparison operator.
TimeInterval operator-(const TimeInterval &) const
Returns the interval difference. Throws on underflow.
bool operator<(const TimeInterval &) const
Comparison operator.
bool operator!=(const TimeInterval &) const
Comparison operator.
void streamOut(std::ostream &) const
Streams out the interval.
bool operator>=(const TimeInterval &) const
Comparison operator.
bool operator<=(const TimeInterval &) const
Comparison operator.
A monotonically increasing subsecond-resolution timestamp, notionally unrelated to time_t.
bool isZero() const noexcept
Returns true if zero().
static TimerTime now()
Factory function for the current steady-clock time.
TimerTime operator+(const TimeInterval &) const
Returns this time with given interval added.
bool operator>(const TimerTime &) const
Comparison operator.
TimeInterval interval(const TimerTime &end) const
Returns the interval between this time and the given end time.
bool operator==(const TimerTime &) const
Comparison operator.
bool operator!=(const TimerTime &) const
Comparison operator.
static bool less(const TimerTime &, const TimerTime &) noexcept(less_noexcept)
Comparison operator.
TimeInterval operator-(const TimerTime &start) const
Returns the given start time's interval() compared to this end time.
bool sameSecond(const TimerTime &other) const
Returns true if this time and the other time are the same, at second resolution.
void operator+=(TimeInterval)
Adds an interval.
static TimerTime zero()
Factory function for the start of the epoch, guaranteed to be less than any now().
bool operator<=(const TimerTime &) const
Comparison operator.
bool operator>=(const TimerTime &) const
Comparison operator.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().