LocalDateTime Class Reference

#include <datetime.h>

详细描述

At some point developers have to deal with times, dates and timezones. This topic can promote headaches because it can be quite complex. In general you have to be aware of differences in timezones, especially when your software runs on mobile devices are you let the user share data across countries (or even within the same country).

In this header file you find some convenient helper functions and classes to reduce the amount of effort you have to put into to handle this topic to a minimum. The implementation and definition of the classes rely on the ISO 8601. Use the UniversalDateTime whenever possible to store normalized time and date values and convert them to a LocalDateTime instance as late as possible (e.g. for a local string output). An object representing a local 'time and date' of the current system time. All members are public and are allowed to be modified for custom needs. Keep in mind that you have to ensure that the values are correct and valid when converting an object back to UniversalDateTime , otherwise the behavior is undefined.

公共成员函数

Bool   IsLeapYear () const
DAYOFWEEK   GetDayOfWeek () const
UniversalDateTime   ConvertToUniversalDateTime () const
Bool   operator== (const LocalDateTime &x) const
Bool   operator!= (const LocalDateTime &x) const
void  重置 ()
String   FormatTime (const Char *formatString) const
String   ToString (const FormatStatement *formatStatement=nullptr) const
HashInt   GetHashCode () const

静态公共成员函数

static TimeValue   GetTimezoneOffset ( Bool *daylightSavingTime=nullptr)
static Bool   IsLeapYear ( Int year)
static DAYOFWEEK   GetDayOfWeek ( Int lYear, Int lMonth, Int lDay)
static LocalDateTime   GetNow ()
static Result < LocalDateTime FromString (const String &dateTimeStr, const Char *formatString)
static Result < LocalDateTime FromValues ( Int32 year, UChar month, UChar day, UChar hour, UChar minute, UChar second, DST daylightSavingTime= DST::AUTOMATIC )
static LocalDateTime   FromUnixTimestamp ( UInt64 timestamp)

Public Attributes

Int32   _year
UChar   _month
UChar   _day
UChar   _hour
UChar   _minute
UChar   _second
DST   _daylightSavingTime

成员函数文档编制

◆  IsLeapYear() [1/2]

Bool IsLeapYear ( ) const

Check if the set year is a leap year.

返回
True for a leap year, otherwise false.

◆  GetDayOfWeek() [1/2]

DAYOFWEEK GetDayOfWeek ( ) const

Return the day of the set time.

返回
See DAYOFWEEK

◆  ConvertToUniversalDateTime()

UniversalDateTime ConvertToUniversalDateTime ( ) const

Converts the local time to the universal date-time

返回
The normalized time.

◆  operator==()

Bool operator== ( const LocalDateTime x ) const

Compare operator ==. The objects must represent a date and time in the same timezone. The Daylight Saving Time is not compared.

返回
True if both UniversalDateTime are identical.

◆  operator!=()

Bool operator!= ( const LocalDateTime x ) const

◆  Reset()

void Reset ( )

Resets the date-time object and sets all members to 0.

◆  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

◆  GetHashCode()

HashInt GetHashCode ( ) const

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

◆  GetTimezoneOffset()

static TimeValue GetTimezoneOffset ( Bool daylightSavingTime = nullptr )
static

Return the current timezone offset to the universal time coordinate (UTC).

参数
[out] daylightSavingTime True if Daylight Saving Time effects the local time.
返回
The timezone offset.

◆  IsLeapYear() [2/2]

static Bool IsLeapYear ( Int   year )
static

Check if the passed year is a leap year.

参数
[in] year Year value.
返回
True for a leap year, otherwise false.

◆  GetDayOfWeek() [2/2]

static DAYOFWEEK GetDayOfWeek ( Int   lYear ,
Int   lMonth ,
Int   lDay  
)
static

Return the day of the passed date.

参数
[in] lYear Year value.
[in] lMonth Month value.
[in] lDay Day value.
返回
See DAYOFWEEK

◆  GetNow()

static LocalDateTime GetNow ( )
static

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

返回
LocalDateTime

◆  FromString()

static Result < LocalDateTime > FromString ( const String dateTimeStr ,
const Char formatString  
)
static

Creates a date-time object by the passed string and its passed format string. An example:

iferr_scope ; LocalDateTime dt = LocalDateTime::FromString (str, "%a, %d %b %Y %H:%M:%S" ) iferr_return ;
参数
[in] dateTimeStr The time string.
[in] formatString The matching format string.
返回
The date-time object or an error if the passed date-time string cannot be resolved by the format string.

◆  FromValues()

static Result < LocalDateTime > FromValues ( Int32   year ,
UChar   month ,
UChar   day ,
UChar   hour ,
UChar   minute ,
UChar   second ,
DST   daylightSavingTime = DST::AUTOMATIC  
)
static

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

警告
The passed values are not checked for their validity!
参数
[in] year Year value [e.g. 2015]
[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]
[in] daylightSavingTime Optional Daylight Saving Time information. See DST.
返回
date-time object.

◆  FromUnixTimestamp()

static LocalDateTime FromUnixTimestamp ( UInt64   timestamp )
static

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

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

Member Data Documentation

◆  _year

Int32 _year

Full year, e.g. 2014.

◆  _month

UChar _month

1..12

◆  _day

UChar _day

1..31

◆  _hour

UChar _hour

0..23

◆  _minute

UChar _minute

0..59

◆  _second

UChar _second

0..59

◆  _daylightSavingTime

DST _daylightSavingTime
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::LocalDateTime::FromString
static Result< LocalDateTime > FromString(const String &dateTimeStr, const Char *formatString)
iferr_scope
#define iferr_scope
定义: resultbase.h:1343