PLCnext API Documentation 25.0.2.69
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
Arp::Base::Core::DateTime Class Reference

This class contains date and time informations. More...

#include <DateTime.hpp>

Public Types

using Value = uint64
 
using Ticks = int64
 

Public Member Functions

 DateTime (void)
 Default constructor.
 
 DateTime (int64 ticks, DateTimeKind kind)
 Constructs an DateTime instance. More...
 
 DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, DateTimeKind kind)
 Initializes a new instance of the T:System.DateTime structure to the specified year, month, day, hour, minute, second and millisecond. More...
 
Ticks GetTicks (void) const
 Gets the ticks of this instance in units of 100 nanoseconds. More...
 
DateTimeKind GetKind (void) const
 Gets the DateTimeKind of this instance. More...
 
int GetYear (void) const
 Gets the year of this instance. More...
 
int GetMonth (void) const
 Gets the month of this instance. More...
 
int GetDay (void) const
 Gets the day of this instance. More...
 
int GetHour (void) const
 Gets the hour of this instance. More...
 
int GetMinute (void) const
 Gets the minute of this instance. More...
 
int GetSecond (void) const
 Gets the second of this instance. More...
 
int GetMillisecond (void) const
 Gets the millisecond of this instance. More...
 
int GetMicrosecond (void) const
 Gets the microsecond of this instance. More...
 
bool IsEmpty (void) const
 Checks if this instance represents a valid date. More...
 
time_t ToUnixTime (void) const
 Converts this instance to unix time (UTC). More...
 
int64 ToUnixTimeMicroseconds (void) const
 Converts this instance to unix time in microseconds (UTC). More...
 
Value ToBinary (void) const
 Converts this instance to its binary representation. More...
 
int64 ToOpcUaTime (void) const
 Converts this instance to OpcUA time (UTC). More...
 
String ToIso8601String (void) const
 Converts this instance to an Iso8601 string . More...
 

Static Public Member Functions

static DateTime GetUtcMin (void)
 Gets the minimal UTC DateTime value. More...
 
static DateTime GetUtcMax (void)
 Gets the maximal UTC DateTime value. More...
 
static int64 GetMinTicks (void)
 Gets the minimum number of ticks. More...
 
static int64 GetMaxTicks (void)
 Gets the maximum number of ticks. More...
 
static DateTime GetUtcNow (void)
 Gets the current time in UTC. More...
 
static DateTime GetLocalNow (void)
 Gets the current time in local time. More...
 
static DateTime FromUnixTime (time_t unixTime)
 Creates a DateTime from the as argument passed unix time. More...
 
static DateTime FromUnixTimeMicroseconds (int64 microseconds)
 Creates a DateTime from the as argument passed unix time in microseconds. More...
 
static DateTime FromOpcUaTime (int64 opcUaTime)
 Creates a DateTime from the argument passed in OpcUA time. More...
 
static DateTime FromIso8601String (const String &input)
 Creates a DateTime from the as argument passed ISO8601 string. More...
 
static DateTime FromBinary (Value value)
 Creates a DateTime from the as argument passed (internal) binary representation. More...
 
static bool IsLeapYear (int year)
 Returns an indication whether the specified year is a leap year. More...
 

Static Public Attributes

static const int64 MinTicks = 0
 DEPRECATED. More...
 
static const int64 MaxTicks = ((((365LL * 4LL + 1LL) * 25LL - 1LL) * 4LL + 1LL) * 25LL - 366LL) * (10LL * 1000LL * 1000LL * 60LL * 60LL * 24LL) - 1LL
 DEPRECATED. More...
 

Friends

class Impl
 
ARP_EXPORT friend bool operator== (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend bool operator!= (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend bool operator> (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend bool operator< (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend bool operator>= (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend bool operator<= (const DateTime &left, const DateTime &right)
 Compares the left DateTime instance to the right one. More...
 
ARP_EXPORT friend std::ostream & operator<< (std::ostream &os, const DateTime &value)
 Writes the DateTime value to the given output streams in Iso8601 format. More...
 
ARP_EXPORT friend std::istream & operator>> (std::istream &is, DateTime &value)
 Reads the DateTime value from the given input streams in Iso8601 format. More...
 

Detailed Description

This class contains date and time informations.

The granularity of the time values is 100 nanoseconds units called ticks. The origin of the dates is 01.01.0001 at 00:00:00. Thus a particular date and time value is the number of ticks from 01.01.0001 at 00:00:00 o'clock. The implementation and internal representation complies to the .NET DateTime class, see https://docs.microsoft.com/de-de/dotnet/api/system.datetime?view=netframework-4.7.2.

Constructor & Destructor Documentation

◆ DateTime() [1/2]

Arp::DateTime::DateTime ( int64  ticks,
DateTimeKind  kind 
)

Constructs an DateTime instance.

Parameters
ticksThe ticks to initialize the DateTime with.
kindThe DateTimeKind to initialize the DateTime with.

◆ DateTime() [2/2]

Arp::DateTime::DateTime ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  millisecond,
int  microsecond,
DateTimeKind  kind 
)

Initializes a new instance of the T:System.DateTime structure to the specified year, month, day, hour, minute, second and millisecond.

Parameters
yearThe year (1 through 9999).
monthThe month (1 through 12).
dayThe day (1 through the number of days in month).
hourThe hours (0 through 23).
minuteThe minutes (0 through 59).
secondThe seconds (0 through 59).
millisecondThe milliseconds (0 through 999).
microsecondThe milliseconds (0 through 999).
kindThe DateTimeKind to initialize the DateTime with.

Member Function Documentation

◆ FromBinary()

DateTime Arp::DateTime::FromBinary ( Value  value)
static

Creates a DateTime from the as argument passed (internal) binary representation.

Parameters
valueThe binary representation to convert to DateTime.
Returns
The a new DateTime representing the given binary representation.

◆ FromIso8601String()

DateTime Arp::DateTime::FromIso8601String ( const String input)
static

Creates a DateTime from the as argument passed ISO8601 string.

Parameters
inputThe ISO8601 time string to convert to DateTime.
Returns
The a new DateTime representing the given string.

◆ FromOpcUaTime()

DateTime Arp::DateTime::FromOpcUaTime ( int64  opcUaTime)
static

Creates a DateTime from the argument passed in OpcUA time.

Parameters
opcUaTimeThe OpcUA time in 100ns ticks since 01.01.1601.
Returns
A new DateTime representing the given OpcUA time.

◆ FromUnixTime()

DateTime Arp::DateTime::FromUnixTime ( time_t  unixTime)
static

Creates a DateTime from the as argument passed unix time.

Parameters
unixTimeThe unix time to convert to DateTime.
Returns
The a new DateTime representing the given unix time.

◆ FromUnixTimeMicroseconds()

DateTime Arp::DateTime::FromUnixTimeMicroseconds ( int64  microseconds)
static

Creates a DateTime from the as argument passed unix time in microseconds.

Parameters
microsecondsThe unix time in microseconds to convert to DateTime.
Returns
A new DateTime representing the given unix time.

◆ GetDay()

int Arp::DateTime::GetDay ( void  ) const

Gets the day of this instance.

Returns
The day of this date.

◆ GetHour()

int Arp::DateTime::GetHour ( void  ) const

Gets the hour of this instance.

Returns
The hour of this time.

◆ GetKind()

DateTimeKind Arp::Base::Core::DateTime::GetKind ( void  ) const

Gets the DateTimeKind of this instance.

Returns
The kind of this instance.

◆ GetLocalNow()

DateTime Arp::Base::Core::DateTime::GetLocalNow ( void  )
static

Gets the current time in local time.

Returns
The current local time.

This operation is not implemented yet and throws an exception.

◆ GetMaxTicks()

int64 Arp::Base::Core::DateTime::GetMaxTicks ( void  )
static

Gets the maximum number of ticks.

Returns
The maximal number of ticks.

◆ GetMicrosecond()

int Arp::DateTime::GetMicrosecond ( void  ) const

Gets the microsecond of this instance.

Returns
The microsecond of this time.

◆ GetMillisecond()

int Arp::DateTime::GetMillisecond ( void  ) const

Gets the millisecond of this instance.

Returns
The millisecond of this time.

◆ GetMinTicks()

int64 Arp::Base::Core::DateTime::GetMinTicks ( void  )
static

Gets the minimum number of ticks.

Returns
The minimal number of ticks.

◆ GetMinute()

int Arp::DateTime::GetMinute ( void  ) const

Gets the minute of this instance.

Returns
The minute of this time.

◆ GetMonth()

int Arp::DateTime::GetMonth ( void  ) const

Gets the month of this instance.

Returns
The month of this date.

◆ GetSecond()

int Arp::DateTime::GetSecond ( void  ) const

Gets the second of this instance.

Returns
The second of this time.

◆ GetTicks()

DateTime::Ticks Arp::Base::Core::DateTime::GetTicks ( void  ) const

Gets the ticks of this instance in units of 100 nanoseconds.

Returns
The internal ticks of this instance.

◆ GetUtcMax()

DateTime Arp::Base::Core::DateTime::GetUtcMax ( void  )
static

Gets the maximal UTC DateTime value.

Returns
The maximal UTC DateTime value.

◆ GetUtcMin()

DateTime Arp::Base::Core::DateTime::GetUtcMin ( void  )
static

Gets the minimal UTC DateTime value.

Returns
The minimal UTC DateTime value.

◆ GetUtcNow()

DateTime Arp::DateTime::GetUtcNow ( void  )
static

Gets the current time in UTC.

Returns
The current UTC time.

◆ GetYear()

int Arp::DateTime::GetYear ( void  ) const

Gets the year of this instance.

Returns
The year of this date.

◆ IsEmpty()

bool Arp::DateTime::IsEmpty ( void  ) const

Checks if this instance represents a valid date.

Returns
true if the objects empty

Only default-constructed objects are empty.

◆ IsLeapYear()

bool Arp::DateTime::IsLeapYear ( int  year)
static

Returns an indication whether the specified year is a leap year.

Parameters
yearA 4-digit year.
Returns
true if year is a leap year, otherwise false.

◆ ToBinary()

uint64 Arp::DateTime::ToBinary ( void  ) const

Converts this instance to its binary representation.

Returns
The binary representation of this instance.

◆ ToIso8601String()

DateTime::String Arp::DateTime::ToIso8601String ( void  ) const

Converts this instance to an Iso8601 string .

Returns
The Iso8601 string representing this instance.

◆ ToOpcUaTime()

int64 Arp::DateTime::ToOpcUaTime ( void  ) const

Converts this instance to OpcUA time (UTC).

Returns
The OpcUA time representing this instance.

◆ ToUnixTime()

time_t Arp::DateTime::ToUnixTime ( void  ) const

Converts this instance to unix time (UTC).

Returns
The unix time representing this instance.

◆ ToUnixTimeMicroseconds()

int64 Arp::DateTime::ToUnixTimeMicroseconds ( void  ) const

Converts this instance to unix time in microseconds (UTC).

Returns
The unix time in microseconds representing this instance.

Friends And Related Function Documentation

◆ operator!=

ARP_EXPORT friend bool operator!= ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is not equal to the right one, otherwise false.

◆ operator<

ARP_EXPORT friend bool operator< ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is less to the right one, otherwise false.

◆ operator<<

ARP_EXPORT friend std::ostream & operator<< ( std::ostream &  os,
const DateTime value 
)
friend

Writes the DateTime value to the given output streams in Iso8601 format.

Parameters
osThe output stream to write to.
valueThe value to write.
Returns
The output stream which was passed as argument.

◆ operator<=

ARP_EXPORT friend bool operator<= ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is less or equal to the right one, otherwise false.

◆ operator==

ARP_EXPORT friend bool operator== ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is equal to the right one, otherwise false.

◆ operator>

ARP_EXPORT friend bool operator> ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is greater to the right one, otherwise false.

◆ operator>=

ARP_EXPORT friend bool operator>= ( const DateTime left,
const DateTime right 
)
friend

Compares the left DateTime instance to the right one.

Parameters
leftThe left operand to compare.
rightThe left operand to compare.
Returns
true if the left operand is greater or equal to the right one, otherwise false.

◆ operator>>

ARP_EXPORT friend std::istream & operator>> ( std::istream &  is,
DateTime value 
)
friend

Reads the DateTime value from the given input streams in Iso8601 format.

Parameters
isThe input stream to read from.
valueThe value to read.
Returns
The input stream which was passed as argument.

Member Data Documentation

◆ MaxTicks

const int64 Arp::Base::Core::DateTime::MaxTicks = ((((365LL * 4LL + 1LL) * 25LL - 1LL) * 4LL + 1LL) * 25LL - 366LL) * (10LL * 1000LL * 1000LL * 60LL * 60LL * 24LL) - 1LL
static

DEPRECATED.

Use DateTime::GetMaxTicks() instead.

◆ MinTicks

const int64 Arp::Base::Core::DateTime::MinTicks = 0
static

DEPRECATED.

Use DateTime::GetMinTicks() instead.


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