UniversalDateTime Class Reference

#include <datetime.h>

Detailed Description

Class that represents the Universal date-time (UTC+0000). This class should be used whenever you store date and time data and should be converted to the LocalDateTime for a local output as late as possible. The internal representation is an unsigned 64-Bit integer and contains the standard Unix date-time starting with 01/01/1970-00:00 UTC+0000. The resolution of this date-time class is 1-second.

Public Member Functions

void Reset ()
 
Float64 GetJulianDay (JULIANDATE variant) const
 
LocalDateTime ConvertToLocalDateTime () const
 
RemoteDateTime ConvertToLocalDateTime (const TimeValue &utcOffset, DST dst) const
 
UInt64 GetUnixTimestamp () const
 
 MAXON_OPERATOR_EQUALITY_HASHCODE (UniversalDateTime, _timestamp)
 
Bool operator< (const UniversalDateTime &x) const
 
 MAXON_OPERATOR_INEQUALITY (UniversalDateTime)
 
UniversalDateTimeoperator+= (const TimeValue &t)
 
UniversalDateTimeoperator-= (const TimeValue &t)
 
UniversalDateTime operator+ (const TimeValue &t) const
 
UniversalDateTime operator- (const TimeValue &t) const
 
Bool IsValid () const
 
Bool IsPopulated () const
 
Bool IsEmpty () const
 
String FormatTime (const Char *formatString) const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 

Static Public Member Functions

static UniversalDateTime GetNow ()
 
static Result< UniversalDateTimeFromValues (Int32 year, UChar month, UChar day, UChar hour, UChar minute, UChar second)
 
static UniversalDateTime FromJulianDay (JULIANDATE variant, Float64 j)
 
static Float64 ToJulianDay (JULIANDATE variant, Int32 year, UChar month, UChar day, UChar hour, UChar minute, UChar second)
 
static UniversalDateTime FromUnixTimestamp (UInt64 timestamp)
 
static Result< void > DescribeIO (const DataSerializeInterface &stream)
 
static MAXON_ATTRIBUTE_FORCE_INLINE const UniversalDateTimeNullValue ()
 

Static Public Attributes

static UniversalDateTime g_nullValue
 

Private Attributes

UInt64 _timestamp
 

Member Function Documentation

◆ Reset()

void Reset ( void  )

Reset all values to zero.

◆ GetJulianDay()

Float64 GetJulianDay ( JULIANDATE  variant) const

Return the Julian day unit of the universal date-time object.

Parameters
[in]variantJulian Date Variant.
Returns
The Julian day unit.

◆ ConvertToLocalDateTime() [1/2]

LocalDateTime ConvertToLocalDateTime ( ) const

Converts the universal date-time to a local date-time object in the current timezone.

Returns
The local date-time.

◆ ConvertToLocalDateTime() [2/2]

RemoteDateTime ConvertToLocalDateTime ( const TimeValue utcOffset,
DST  dst 
) const

Converts the universal date-time to a remote date-time.

Parameters
[in]utcOffsetTimezone offset which will be added to the UTC value.
[in]dstIf set, Daylight Saving Time will be added.
Returns
The remote date-time.

◆ GetUnixTimestamp()

UInt64 GetUnixTimestamp ( ) const

Return the Unix time stamp.

Returns
The Unix time stamp where the value 0 represents the 01/01/1970-00:00 UTC.

◆ MAXON_OPERATOR_EQUALITY_HASHCODE()

MAXON_OPERATOR_EQUALITY_HASHCODE ( UniversalDateTime  ,
_timestamp   
)

◆ operator<()

Bool operator< ( const UniversalDateTime x) const

Compare for less.

Returns
True if both this is less than x.

◆ MAXON_OPERATOR_INEQUALITY()

MAXON_OPERATOR_INEQUALITY ( UniversalDateTime  )

◆ operator+=()

UniversalDateTime& operator+= ( const TimeValue t)

◆ operator-=()

UniversalDateTime& operator-= ( const TimeValue t)

◆ operator+()

UniversalDateTime operator+ ( const TimeValue t) const

◆ operator-()

UniversalDateTime operator- ( const TimeValue t) const

◆ IsValid()

Bool IsValid ( ) const

Check if the UniversalDateTime has a timestamp greater than 0. Even 0 is a valid timestamp this function can be used to determine if the time object has a proper value.

Returns
True if some date or time is set in the structure.

◆ IsPopulated()

Bool IsPopulated ( void  ) const

◆ IsEmpty()

Bool IsEmpty ( ) const

◆ FormatTime()

String FormatTime ( const Char formatString) const

Formats the time into a specific format defined be the format string.

Parameters
[in]formatStringOptional. OS depending C lib format string (see strftime). "%Y-%m-%d %H:%M:%S" is used if formatString is nullptr.
Returns
Formated String of the date-time.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. See also Formatting Floating point values.
Returns
The converted result.

◆ GetNow()

static UniversalDateTime GetNow ( )
static

Return the current date-time object of the current time zone.

Returns
The current date-time.

◆ FromValues()

static Result<UniversalDateTime> FromValues ( Int32  year,
UChar  month,
UChar  day,
UChar  hour,
UChar  minute,
UChar  second 
)
static

Creates a universal date-time object by the passed date values.

Warning
The year is the only checked parameter for validity!
Parameters
[in]yearYear value [1970-3000]
[in]monthMonth value value [1-12]
[in]dayDay value [1-31]
[in]hourHour value [0-23]
[in]minuteMinute value [0-59]
[in]secondSecond value [0-59]
Returns
date-time object.

◆ FromJulianDay()

static UniversalDateTime FromJulianDay ( JULIANDATE  variant,
Float64  j 
)
static

Creates a date-time object by the passed Julian day.

Parameters
[in]variantJulian Date Variant.
[in]jThe Julian day value.
Returns
See LocalDateTime

◆ ToJulianDay()

static Float64 ToJulianDay ( JULIANDATE  variant,
Int32  year,
UChar  month,
UChar  day,
UChar  hour,
UChar  minute,
UChar  second 
)
static

Creates a Julian date value from single date components. Prefer using this function when you need to convert date-components to julian date, because UniversalDateTime cannot cover years older than 1970 so UniversalDateTime::GetJulianDay would fail.

Parameters
[in]variantJulian Date Variant.
[in]yearYear value [1970-3000]
[in]monthMonth value value [1-12]
[in]dayDay value [1-31]
[in]hourHour value [0-23]
[in]minuteMinute value [0-59]
[in]secondSecond value [0-59]
Returns
The Julian date.

◆ FromUnixTimestamp()

static UniversalDateTime FromUnixTimestamp ( UInt64  timestamp)
static

Create a universal date-time object by passing a Unix time stamp.

Parameters
[in]timestampThe Unix time stamp where value 0 represents the 01/01/1970-00:00 UTC.
Returns
The universal date-time object.

◆ DescribeIO()

static Result<void> DescribeIO ( const DataSerializeInterface stream)
static

Describe all elements of this class for I/O operations.

Parameters
[in]streamThe stream that is used to register the class members.
Returns
OK on success.

◆ NullValue()

static MAXON_ATTRIBUTE_FORCE_INLINE const UniversalDateTime& NullValue ( )
static

Returns a null value of the UniversalDateTime (see nullvalue.h for more details).

Returns
A null value of the UniversalDateTime.

Member Data Documentation

◆ g_nullValue

UniversalDateTime g_nullValue
static

◆ _timestamp

UInt64 _timestamp
private