ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::time::DateTime Class Reference

Description:

This class provides an interface into the system's clock values. In contrast to values of sibling class Ticks, the underlying system timer is not guaranteed to be steady. This means that an object created or set at a later point in time of the program execution, might represent an earlier point in time. This might happen when the system clock gets adjusted in-between two measurements.

Therefore, the class is to be used to represent calendar clock values which usually get converted to human-readable formats (calendar dates and 24/60/60 clock times).

Apart from a few system-dependent conversion methods, the class has no specific interface, but the methods and operators inherited from base TimePointBase.

To construct an object of this type using calendrical date and time values, helper-class CalendarDateTime with its constructor CalendarDateTime(int,int,int,int,int,int,int) is available in case module ALib Strings is included in the ALib Build. A typical construction with this helper could look like this:

 DateTime myDate= CalendarDateTime(2025,1,31,14,5).Get( Timezone::UTC );
See also
For this class, a pretty printer for the GNU debugger is provided.

Definition at line 36 of file datetime.inl.

Inheritance diagram for alib::time::DateTime:
[legend]
Collaboration diagram for alib::time::DateTime:
[legend]

Public Static Method Index:

static DateTime FromEpochSeconds (time_t epochSeconds)
 
static ALIB_DLL DateTime FromFileTime (const FILETIME &fileTime)
 
static ALIB_DLL DateTime FromFileTime (const ULARGE_INTEGER &fileTime)
 
static ALIB_DLL DateTime FromSystemTime (const SYSTEMTIME &systemTime, lang::Timezone timezone=lang::Timezone::Local)
 
- Public Static Method Index: inherited from alib::time::TimePointBase< std::chrono::system_clock, DateTime >
static DateTime BeginningOfEpoch ()
 
static DateTime EndOfEpoch ()
 
static DateTime FromRaw (TRaw raw)
 
static DateTime Now ()
 

Public Method Index:

time_t InEpochSeconds () const
 
bool operator!= (const DateTime &other) const
 
bool operator< (const DateTime &other) const
 
bool operator<= (const DateTime &other) const
 
bool operator== (const DateTime &other) const
 
bool operator> (const DateTime &other) const
 
bool operator>= (const DateTime &other) const
 
ALIB_DLL FILETIME ToFileTime () const
 
ALIB_DLL ULARGE_INTEGER ToFileTimeLI () const
 
ALIB_DLL SYSTEMTIME ToSystemTime (lang::Timezone timezone=lang::Timezone::Local) const
 
- Public Method Index: inherited from alib::time::TimePointBase< std::chrono::system_clock, DateTime >
constexpr TimePointBase (const lang::Initialization init=lang::Initialization::Default)
 
constexpr TimePointBase (TTimePoint internalValue)
 
Duration Age () const
 
TTimePoint Export () const
 
void Import (TTimePoint timePoint)
 
bool IsOlderThan (const Duration &timeSpan) const
 
bool IsSet ()
 
DateTime operator+ (const Duration &timeSpan) const
 
DateTime operator+ (const typename Duration::TDuration &timeSpan) const
 
DateTime operator+= (const Duration &timeSpan)
 
DateTime operator+= (const typename Duration::TDuration &timeSpan)
 
Duration operator- (const DateTime &other) const
 
DateTime operator- (const Duration &timeSpan) const
 
DateTime operator- (const typename Duration::TDuration &timeSpan) const
 
DateTime operator-= (const Duration &timeSpan)
 
DateTime operator-= (const typename Duration::TDuration &timeSpan)
 
DateTimeReset ()
 
void SetAs (const DateTime &other)
 
void SetFromRaw (TRaw raw)
 
Duration Since (const DateTime &other) const
 
TRaw ToRaw () const
 
void Unset ()
 

Additional Inherited Members

- Public Type Index: inherited from alib::time::TimePointBase< std::chrono::system_clock, DateTime >
using TRaw
 Integral type used for exporting and importing values in raw units.
 
using TTimePoint
 The internal c++ type for time points.
 
- Protected Field Index: inherited from alib::time::TimePointBase< std::chrono::system_clock, DateTime >
TTimePoint stamp
 

Method Details:

◆ FromEpochSeconds()

DateTime alib::time::DateTime::FromEpochSeconds ( time_t epochSeconds)
inlinestatic

Static method that creates a DateTime object representing the given system point in time measured in seconds since January 1st 1970, 00:00:00 GMT.

Parameters
epochSecondsThe milliseconds in the epoch to convert.
Returns
A time stamp object

Definition at line 70 of file datetime.inl.

◆ FromFileTime() [1/2]

ALIB_DLL DateTime alib::time::DateTime::FromFileTime ( const FILETIME & fileTime)
static

Static method that creates a DateTime object representing the given "file time". File time is a 64-bit value that represents the number of 100 nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 UTC.

Note
Microsoft Windows specific.
Parameters
fileTimeThe file time to use.
Returns
A time stamp object

◆ FromFileTime() [2/2]

ALIB_DLL DateTime alib::time::DateTime::FromFileTime ( const ULARGE_INTEGER & fileTime)
static

Static method that creates a DateTime object representing the given "file time". File time is a 64-bit value that represents the number of 100 nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 UTC.

Note
Microsoft Windows specific.
Parameters
fileTimeThe file time to use.
Returns
A time stamp object

◆ FromSystemTime()

ALIB_DLL DateTime alib::time::DateTime::FromSystemTime ( const SYSTEMTIME & systemTime,
lang::Timezone timezone = lang::Timezone::Local )
static

Static method that creates a DateTime object representing the given as windows system time.

Note
Microsoft Windows specific.
Parameters
systemTimePointer to a SYSTEMTIME struct that holds the system time to use.
timezoneDenote if the time is interpreted as local or UTC. Defaults to TimeZone::Local.
Returns
Seconds in the epoch.

◆ InEpochSeconds()

time_t alib::time::DateTime::InEpochSeconds ( ) const
inline

Converts the internal value into seconds since January 1, 1970, 00:00:00 GMT. The conversion is dependent on time zone and system clock setting of the host.

Returns
Seconds in the epoch.

Definition at line 56 of file datetime.inl.

◆ operator!=()

bool alib::time::DateTime::operator!= ( const DateTime & other) const
inline

Not equal to operator.

Parameters
otherThe time stamp to compare.
Returns
The result of the comparison.

Definition at line 175 of file datetime.inl.

◆ operator<()

bool alib::time::DateTime::operator< ( const DateTime & other) const
inline

Less than operator.

Parameters
otherThe time stamp to compare.
Returns
A reference to this object.

Definition at line 185 of file datetime.inl.

◆ operator<=()

bool alib::time::DateTime::operator<= ( const DateTime & other) const
inline

Less than or equal to operator.

Parameters
otherThe time stamp to compare.
Returns
The result of the comparison.

Definition at line 195 of file datetime.inl.

◆ operator==()

bool alib::time::DateTime::operator== ( const DateTime & other) const
inline

Equal to operator.

Parameters
otherThe time stamp to compare.
Returns
The result of the comparison.

Definition at line 164 of file datetime.inl.

◆ operator>()

bool alib::time::DateTime::operator> ( const DateTime & other) const
inline

Greater than operator.

Parameters
otherThe time stamp to compare.
Returns
The result of the comparison.

Definition at line 205 of file datetime.inl.

◆ operator>=()

bool alib::time::DateTime::operator>= ( const DateTime & other) const
inline

Greater than or equal to operator.

Parameters
otherThe time stamp to compare.
Returns
The result of the comparison.

Definition at line 215 of file datetime.inl.

◆ ToFileTime()

ALIB_DLL FILETIME alib::time::DateTime::ToFileTime ( ) const

Converts the internal value into windows specific file time, a 64-bit value that represents the number of 100 nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 UTC. The conversion is dependent on time zone and system clock setting of the host.

Note
Microsoft Windows specific.
Returns
The Windows OS file time value represented by this object.

◆ ToFileTimeLI()

ALIB_DLL ULARGE_INTEGER alib::time::DateTime::ToFileTimeLI ( ) const

Converts the internal value into windows specific file time, a 64-bit value that represents the number of 100 nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 UTC. The conversion is dependent on time zone and system clock setting of the host.

Note
Microsoft Windows specific.
Returns
The Windows OS file time represented by this object as type struct ULARGE_INTEGER.

◆ ToSystemTime()

ALIB_DLL SYSTEMTIME alib::time::DateTime::ToSystemTime ( lang::Timezone timezone = lang::Timezone::Local) const

Converts the internal value into windows specific system time struct.

Note
Microsoft Windows specific.
Parameters
timezoneDenote if the time that is returned should be local or UTC. Defaults to TimeZone::Local.
Returns
The time point as SYSTEMTIME.

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