UniversalDateTime Class Reference

#include <datetime.h>

详细描述

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.

公共成员函数

void  重置 ()
Float64   GetJulianDay ( JULIANDATE variant) const
LocalDateTime   ConvertToLocalDateTime () const
RemoteDateTime   ConvertToLocalDateTime (const TimeValue &utcOffset, DST dst) const
UInt64   GetUnixTimestamp () const
Bool   operator== (const UniversalDateTime &x) const
Bool   operator< (const UniversalDateTime &x) const
UniversalDateTime operator+= (const TimeValue &t)
UniversalDateTime operator-= (const TimeValue &t)
UniversalDateTime   operator+ (const TimeValue &t) const
UniversalDateTime   operator- (const TimeValue &t) const
  MAXON_OPERATOR_COMPARISON ( UniversalDateTime )
Bool   IsValid () const
String   FormatTime (const Char *formatString) const
String   ToString (const FormatStatement *formatStatement=nullptr) const
HashInt   GetHashCode () const

静态公共成员函数

static UniversalDateTime   GetNow ()
static Result < UniversalDateTime FromValues ( 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 const UniversalDateTime NullValue ()

静态公共属性

static UniversalDateTime   g_nullValue

Private Attributes

UInt64   _timestamp

成员函数文档编制

◆  Reset()

void Reset ( )

Reset all values to zero.

◆  GetJulianDay()

Float64 GetJulianDay ( JULIANDATE   variant ) const

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

参数
[in] variant Julian Date Variant.
返回
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.

返回
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.

参数
[in] utcOffset Timezone offset which will be added to the UTC value.
[in] dst If set, Daylight Saving Time will be added.
返回
The remote date-time.

◆  GetUnixTimestamp()

UInt64 GetUnixTimestamp ( ) const

Return the Unix time stamp.

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

◆  operator==()

Bool operator== ( const UniversalDateTime x ) const

Compare operator ==.

返回
True if both UniversalDateTime are identical.

◆  operator<()

Bool operator< ( const UniversalDateTime x ) const

Compare for less.

返回
True if both this is less than x.

◆  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

◆  MAXON_OPERATOR_COMPARISON()

MAXON_OPERATOR_COMPARISON ( UniversalDateTime   )

◆  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.

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

◆  FormatTime()

String FormatTime ( const Char formatString ) const

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

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

◆  ToString()

String ToString ( const FormatStatement formatStatement = nullptr ) const

Returns a readable string of the content.

参数
[in] formatStatement Nullptr or additional formatting instruction. See also Formatting Floating point values .
返回
The converted result.

◆  GetHashCode()

HashInt GetHashCode ( ) const

Returns the hash value of this object. This value can be used for all HashSet<>/HashMap<> classes.

◆  GetNow()

static UniversalDateTime GetNow ( )
static

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

返回
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.

警告
The year is the only checked parameter for validity!
参数
[in] year Year value [1970-3000]
[in] month Month value value [1-12]
[in] day Day value [1-31]
[in] hour Hour value [0-23]
[in] minute Minute value [0-59]
[in] second Second value [0-59]
返回
date-time object.

◆  FromJulianDay()

static UniversalDateTime FromJulianDay ( JULIANDATE   variant ,
Float64   j  
)
static

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

参数
[in] variant Julian Date Variant.
[in] j The Julian day value.
返回
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.

参数
[in] variant Julian Date Variant.
[in] year Year value [1970-3000]
[in] month Month value value [1-12]
[in] day Day value [1-31]
[in] hour Hour value [0-23]
[in] minute Minute value [0-59]
[in] second Second value [0-59]
返回
The Julian date.

◆  FromUnixTimestamp()

static UniversalDateTime FromUnixTimestamp ( UInt64   timestamp )
static

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

参数
[in] timestamp The Unix time stamp where value 0 represents the 01/01/1970-00:00 UTC.
返回
The universal date-time object.

◆  DescribeIO()

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

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

参数
[in] stream The stream that is used to register the class members.
返回
OK on success.

◆  NullValue()

static const UniversalDateTime & NullValue ( )
static

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

返回
A null value of the UniversalDateTime .

Member Data Documentation

◆  g_nullValue

UniversalDateTime g_nullValue static

◆  _timestamp

UInt64 _timestamp
private