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 ;
126 friend class G::DateTimeTest ;
127 struct std::tm m_tm{} ;
142 explicit SystemTime( std::time_t ,
unsigned long us = 0UL ) noexcept ;
160 unsigned int ms()
const ;
163 unsigned int us()
const ;
166 std::time_t
s()
const noexcept ;
210 friend class G::DateTimeTest ;
211 using time_point_type = std::chrono::time_point<std::chrono::system_clock> ;
212 using duration_type = time_point_type::duration ;
217 time_point_type m_tp ;
227 using time_point_type = std::chrono::time_point<std::chrono::steady_clock> ;
236 bool isZero()
const noexcept ;
243 static constexpr bool less_noexcept =
noexcept(time_point_type() < time_point_type()) ;
282 friend class G::DateTimeTest ;
283 using duration_type = time_point_type::duration ;
286 unsigned long s()
const ;
287 unsigned long us()
const ;
288 std::string str()
const ;
291 time_point_type m_tp ;
301 using s_type =
unsigned int ;
302 using us_type =
unsigned int ;
321 unsigned int s()
const ;
324 unsigned int us()
const ;
362 static void increase(
unsigned int &
s ,
unsigned int ds = 1U ) ;
363 static void decrease(
unsigned int &
s ,
unsigned int ds = 1U ) ;
376 G_EXCEPTION_CLASS( Error ,
tx(
"date/time error") ) ;
377 using Offset = std::pair<bool,unsigned int> ;
398 std::ostream & operator<<( std::ostream & ,
const SystemTime & ) ;
399 std::ostream & operator<<( std::ostream & ,
const TimeInterval & ) ;
400 inline bool operator<(
const TimerTime & a ,
const TimerTime & b )
noexcept(TimerTime::less_noexcept)
408 return a.m_tp < b.m_tp ;
An encapsulation of 'struct std::tm'.
int wday() const
Returns week day where sunday=0 and saturday=6.
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.
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.
bool sameMinute(const BrokenDownTime &other) const noexcept
Returns true if this and the other broken-down times are the same, at minute resolution with no round...
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.
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)
A briefer alternative to G::gettext_noop().