7 #include "Arp/System/Core/PrimitiveTypes.hpp"
11 #ifndef ARP_INSIDE_ARP_H
12 #error Never include 'DateTime.hpp' directly, just include 'Arp.h'
136 ARP_DEPRECATED(
"Use FromUnixTimeMicroseconds instead")
229 friend
std::ostream& operator<<(
std::ostream& os, const
DateTime& dateTime);
230 friend
std::istream& operator>>(
std::istream& is,
DateTime& dateTime);
233 int GetDatePart(
int part)const;
236 static
int64 DateToTicks(
int year,
int month,
int day);
237 static
int64 TimeToTicks(
int hour,
int minute,
int second);
238 static
int64 TimeToTicks(
int hour,
int minute,
int second,
int millisecond,
int microsecond);
248 static const
int kindShift = 62;
249 static const
uint64 kindMask = 3ULL << kindShift;
250 static const
uint64 ticksMask = ~kindMask;
253 static const
int64 ticksPerMicrosecond = 10;
254 static const
int64 ticksPerMillisecond = ticksPerMicrosecond * 1000;
255 static const
int64 ticksPerSecond = ticksPerMillisecond * 1000;
256 static const
int64 ticksPerMinute = ticksPerSecond * 60;
257 static const
int64 ticksPerHour = ticksPerMinute * 60;
258 static const
int64 ticksPerDay = ticksPerHour * 24;
261 static const
int daysPerYear = 365;
263 static const
int daysPer4Years = daysPerYear * 4 + 1;
265 static const
int daysPer100Years = daysPer4Years * 25 - 1;
267 static const
int daysPer400Years = daysPer100Years * 4 + 1;
270 static const
int daysTo1970 = daysPer400Years * 4 + daysPer100Years * 3 + daysPer4Years * 17 + daysPerYear;
272 static const
int daysTo1601 = daysPer400Years * 4;
274 static const
int daysTo10000 = daysPer400Years * 25 - 366;
276 static const
int daysToMonth365[];
277 static const
int daysToMonth366[];
279 static const
int datePartYear = 0;
280 static const
int datePartMonth = 2;
281 static const
int datePartDayOfYear = 1;
282 static const
int datePartDay = 3;
285 static const
int64 unix0Ticks = daysTo1970 * ticksPerDay;
286 static const
int64 opcua0Ticks = daysTo1601 * ticksPerDay;
336 return (
int64)(this->data & ticksMask);
The class contains date and time informations.
Definition: DateTime.hpp:45
uint64 ToBinary(void) const
Converts this instance to a binary representation.
static DateTime FromIso8601String(const String &value)
Creates a DateTime from the as argument passed ISO8601 string.
int64 ToUnixTimeMicroseconds(void) const
Converts this instance to unix time (UTC) in microseconds.
static const int64 MaxTicks
The maximal tick count.
Definition: DateTime.hpp:294
int GetDay(void) const
Gets the day of the month component of the date represented by this instance.
DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond, DateTimeKind kind=DateTimeKind::Unspecified)
Initializes a new instance of the T:System.DateTime structure to the specified year,...
~DateTime(void)=default
Destructs this instance and frees all resources.
int GetMillisecond(void) const
Gets the millisecond component of the date represented by this instance.
static DateTime FromOpcUaTime(int64 opcUaTime)
Creates a DateTime from the argument passed in OpcUA time.
static const int64 MinTicks
The minimal tick count.
Definition: DateTime.hpp:291
static DateTime FromUnixTimeMicroseconds(int64 microseconds)
Creates a DateTime from the as argument passed unix time in microseconds.
String ToIso8601String(void) const
Converts this instance to an ISO8601 string .
int GetYear(void) const
Gets the year component of the date represented by this instance.
DateTime(int64 ticks, DateTimeKind kind=DateTimeKind::Unspecified)
Constructs an DateTime instance.
friend std::istream & operator>>(std::istream &is, DateTime &dateTime)
The istream operator is used for string parsing and expects the ISO-8601 format.
Definition: DateTime.hpp:357
int64 ToOpcUaTime(void) const
Converts this instance to OPC time (UTC).
int GetMinute(void) const
Gets the minute component of the date represented by this instance.
DateTime & operator=(const DateTime &arg)=default
The default assignment operator.
int GetHour(void) const
Gets the hour component of the date represented by this instance.
static DateTime Now(void)
Gets the current time as DateTime, expressed as the UTC time.
friend std::ostream & operator<<(std::ostream &os, const DateTime &dateTime)
The ostream operator is used for logging and string formatting and formats the DateTime value in ISO-...
Definition: DateTime.hpp:350
static bool IsLeapYear(int year)
Returns an indication whether the specified year is a leap year.
time_t ToUnixTime(void) const
Converts this instance to unix time (UTC).
static DateTime FromUnixTime(time_t unixTime)
Creates a DateTime from the as argument passed unix time.
uint64 ToUnixMicrosecondTicks(void) const
Converts this instance to unix time (UTC) in microseconds.
static DateTime FromBinary(uint64 data)
Creates a DateTime from the as argument passed binary representation.
int GetSecond(void) const
Gets the second component of the date represented by this instance.
int GetMonth(void) const
Gets the month component of the date represented by this instance.
int GetMicrosecond(void) const
Gets the microsecond component of the date represented by this instance.
DateTime(const DateTime &arg)=default
The default copy constructor.
bool operator!=(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:309
int64 GetTicks(void) const
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.hpp:334
bool operator<(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:319
bool operator==(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:304
DateTimeKind
Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC),...
Definition: DateTime.hpp:26
bool operator>(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:314
bool operator>=(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:324
std::uint64_t uint64
The Arp unsigned integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:39
bool operator<=(const DateTime &arg) const
Compares the ticks of this instance to arg .
Definition: DateTime.hpp:329
std::int64_t int64
The Arp integer type of 8 byte size.
Definition: PrimitiveTypes.hpp:41
DateTimeKind GetKind(void) const
Gets a value that indicates whether the time represented by this instance is based on local time,...
Definition: DateTime.hpp:339
static DateTime FromUnixMicrosecondTicks(uint64 microseconds)
Creates a DateTime from the as argument passed unix time in microseconds.
Definition: DateTime.hpp:344
DateTime(void)
Constructs an zero'ed DateTime instance.
Definition: DateTime.hpp:299
@ Unspecified
Kind of time in not specified
Root namespace for the PLCnext API
Namespace of the C++ standard library