AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::date::DateTime Class Reference

Point in time. More...

#include <dateTime.hpp>

Collaboration diagram for anch::date::DateTime:

Public Member Functions

constexpr DateTime () noexcept
 DateTime (const std::chrono::system_clock::time_point &time)
 DateTime (const std::time_t &time)
 DateTime (const std::tm *const time)
 DateTime (const std::timespec &time)
 DateTime (const anch::date::DateFields &fields)
anch::date::DateFields fields (anch::date::Zone zone=anch::date::Zone::LOCAL) const
bool after (const DateTime &date) const noexcept
bool before (const DateTime &date) const noexcept
bool equals (const DateTime &date) const noexcept
anch::date::Date date (anch::date::Zone zone=anch::date::Zone::LOCAL) const
anch::date::Time time (anch::date::Zone zone=anch::date::Zone::LOCAL) const
anch::date::OffsetTime offsetTime (anch::date::Zone zone=anch::date::Zone::LOCAL) const
std::strong_ordering operator<=> (const DateTime &date) const noexcept
bool operator== (const DateTime &date) const noexcept
 operator std::chrono::system_clock::time_point () const noexcept
 operator std::time_t () const noexcept
 operator std::tm () const noexcept
 operator std::timespec () const noexcept

Static Public Member Functions

static DateTime now ()

Detailed Description

Point in time.

A DateTime is a point in time with a nanosecond precision, stored as a number of nanoseconds since epoch (which covers years 1678 to 2261). Its broken down representation ( fields ) is computed in local time or UTC: local time is computed with localtime_r (std::chrono time zones are not available with GCC 13): it is thread safe and follows the TZ environment variable.
A default DateTime is epoch: the current time is now . DateTime can be converted from and to std::chrono::system_clock::time_point , std::time_t , std::tm and std::timespec . Its day is a Date ( date ).

Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ DateTime() [1/6]

anch::date::DateTime::DateTime ( )
constexprnoexcept

DateTime default constructor: epoch (the current time is now )

◆ DateTime() [2/6]

anch::date::DateTime::DateTime ( const std::chrono::system_clock::time_point & time)
explicit

DateTime constructor

Parameters
timethe time point to set
Since
0.2
Here is the call graph for this function:

◆ DateTime() [3/6]

anch::date::DateTime::DateTime ( const std::time_t & time)
explicit

DateTime constructor

Parameters
timethe time to set
Exceptions
std::invalid_argumentdate out of range (years 1678 to 2261: timestamps are stored in nanoseconds)
Here is the call graph for this function:

◆ DateTime() [4/6]

anch::date::DateTime::DateTime ( const std::tm *const time)
explicit

DateTime constructor

Parameters
timethe local time to set (tm_isdst has to be -1 when daylight saving time is unknown ; tm_wday and tm_yday are ignored ; out of range fields are normalized as std::mktime does)
Exceptions
std::invalid_argumentdate out of range (years 1678 to 2261)
Here is the call graph for this function:

◆ DateTime() [5/6]

anch::date::DateTime::DateTime ( const std::timespec & time)
explicit

DateTime constructor

Parameters
timethe time to set (tv_nsec in [0, 999999999])
Exceptions
std::invalid_argumentdate out of range (years 1678 to 2261) or invalid tv_nsec
Here is the call graph for this function:

◆ DateTime() [6/6]

anch::date::DateTime::DateTime ( const anch::date::DateFields & fields)
explicit

DateTime constructor

Parameters
fieldsthe local time (out of range fields are normalized as std::mktime does ; weekday and yearday are ignored)
Exceptions
std::invalid_argumentdate out of range (years 1678 to 2261)
Since
0.3
Here is the call graph for this function:

Member Function Documentation

◆ after()

bool anch::date::DateTime::after ( const DateTime & date) const
noexcept

Check if current DateTime is after another one.

Parameters
datethe other DateTime
Returns
true if current DateTime is after the other one, false otherwise.
Here is the call graph for this function:

◆ before()

bool anch::date::DateTime::before ( const DateTime & date) const
noexcept

Check if current DateTime is before another one.

Parameters
datethe other DateTime
Returns
true if current DateTime is before the other one, false otherwise.
Here is the call graph for this function:

◆ date()

anch::date::Date anch::date::DateTime::date ( anch::date::Zone zone = anch::date::Zone::LOCAL) const

Day of this point in time

Parameters
zonethe time zone of the day (default local time)
Returns
the day
Since
0.3
Here is the call graph for this function:

◆ equals()

bool anch::date::DateTime::equals ( const DateTime & date) const
noexcept

Check if current DateTime is equals to another one.

Parameters
datethe other DateTime
Returns
true if current DateTime is equals to the other one, false otherwise.
Here is the call graph for this function:

◆ fields()

anch::date::DateFields anch::date::DateTime::fields ( anch::date::Zone zone = anch::date::Zone::LOCAL) const

Broken down date and time

Parameters
zonethe time zone (default local time)
Returns
the fields
Since
0.3
Here is the call graph for this function:

◆ now()

DateTime anch::date::DateTime::now ( )
static

Current point in time

Returns
now
Since
0.3
Here is the call graph for this function:

◆ offsetTime()

anch::date::OffsetTime anch::date::DateTime::offsetTime ( anch::date::Zone zone = anch::date::Zone::LOCAL) const

Time of day of this point in time with the offset of a time zone

Parameters
zonethe time zone (default local time ; historic offsets with seconds are truncated to the minute, the written time is shifted, as rfc3339::formatDateTime does)
Returns
the time of day and its offset from UTC
Since
0.3
Here is the call graph for this function:

◆ operator std::chrono::system_clock::time_point()

anch::date::DateTime::operator std::chrono::system_clock::time_point ( ) const
explicitnoexcept

Cast operator to std::chrono::system_clock::time_point

Returns
the time point
Since
0.2
Here is the call graph for this function:

◆ operator std::time_t()

anch::date::DateTime::operator std::time_t ( ) const
explicitnoexcept

Cast operator to std::time_t (sub-second part is truncated toward the past)

Returns
the converted std::time_t
Here is the call graph for this function:

◆ operator std::timespec()

anch::date::DateTime::operator std::timespec ( ) const
explicitnoexcept

Cast operator to std::timespec

Returns
the converted std::timespec
Here is the call graph for this function:

◆ operator std::tm()

anch::date::DateTime::operator std::tm ( ) const
explicitnoexcept

Cast operator to std::tm (local time, with tm_wday , tm_yday and tm_isdst )

Returns
the converted std::tm
Here is the call graph for this function:

◆ operator<=>()

std::strong_ordering anch::date::DateTime::operator<=> ( const DateTime & date) const
noexcept

Compare dates (with nanosecond precision)

Parameters
datethe date to compare to
Returns
the comparison result
Here is the call graph for this function:

◆ operator==()

bool anch::date::DateTime::operator== ( const DateTime & date) const
noexcept

Check if dates are equals (with nanosecond precision)

Parameters
datethe date to compare to
Returns
true when dates are equals, false otherwise
Here is the call graph for this function:

◆ time()

anch::date::Time anch::date::DateTime::time ( anch::date::Zone zone = anch::date::Zone::LOCAL) const

Time of day of this point in time

Parameters
zonethe time zone (default local time)
Returns
the time of day
Since
0.3
Here is the call graph for this function:

The documentation for this class was generated from the following file: