C++ Based OPC UA Client/Server SDK  1.5.5.355

Wrapper class for the UA stack structure OpcUa_DateTime. More...

#include <uadatetime.h>

Public Member Functions

 UaDateTime ()
 Creates a UaDateTime object initialized with a null value.
 
 UaDateTime (const OpcUa_DateTime &)
 Creates a UaDateTime object initialized with the passed OpcUa_DateTime structure. More...
 
virtual ~UaDateTime ()
 Destroys the UaDateTime object.
 
 UaDateTime (const FILETIME &)
 Creates a UaDateTime object initialized with the passed Windows FILETIME value. More...
 
UaDateTimeoperator= (const FILETIME &)
 Assign a new time using Windows FILETIME value. More...
 
 operator FILETIME () const
 Get the time as Windows FILETIME value. More...
 
 UaDateTime (const OpcUa_Int64 &)
 Creates a UaDateTime object initialized with the passed Int64 value. More...
 
UaDateTimeoperator= (const OpcUa_Int64 &)
 Assign a new time using a OpcUa_Int64 value. More...
 
 operator OpcUa_Int64 () const
 Get the time as Int64 value. More...
 
 operator OpcUa_DateTime () const
 Get the time as OpcUa_DateTime structure. More...
 
bool operator< (const UaDateTime &other) const
 Less than operator for comparing two date/time values. More...
 
bool operator> (const UaDateTime &other) const
 Greater than operator for comparing two date/time values. More...
 
bool operator== (const UaDateTime &other) const
 Equals operator for comparing two date/time values. More...
 
bool operator!= (const UaDateTime &other) const
 Not Equals operator for comparing two date/time values. More...
 
UaString toString () const
 Converts the UaDateTime into a UaString. More...
 
UaString toDateString () const
 Converts the date part of the UaDateTime into a UaString. More...
 
UaString toTimeString () const
 Converts the time part of the UaDateTime into a UaString. More...
 
time_t toTime_t () const
 Converts the UaDateTime value to UNIX timestamp format time_t. More...
 
int msec () const
 Returns the milliseconds part of the UaDateTime object. More...
 
OpcUa_Boolean isNull () const
 Checks whether UaDateTime is null or not. More...
 
OpcUa_Int32 daysTo (const UaDateTime &) const
 Returns the days from the own time value to the passed time value. More...
 
OpcUa_Int32 secsTo (const UaDateTime &) const
 Returns the seconds from the own time value to the passed time value. More...
 
OpcUa_Int64 msecsTo (const UaDateTime &) const
 Returns the milliseconds from the own time value to the passed time value. More...
 
void addSecs (int secs)
 Adds the passed number of seconds to the date/time value. More...
 
void addMilliSecs (int msecs)
 Adds the passed number of milliseconds to the date/time value. More...
 
void copyTo (OpcUa_DateTime *copy) const
 Copy the internal date/time value into an OpcUa_DateTime structure.
 
void toVariant (UaVariant &variant) const
 Copies the internal date/time value to a UaVariant.
 
void toVariant (OpcUa_Variant &variant) const
 Copies the internal date/time value to a OpcUa_Variant structure.
 
void toDataValue (UaDataValue &dataValue, OpcUa_Boolean updateTimeStamps) const
 Copies the internal date/time value to a UaDataValue. More...
 
void toDataValue (OpcUa_DataValue &dataValue, OpcUa_Boolean updateTimeStamps) const
 Copies the internal date/time value to a OpcUa_DataValue structure. More...
 

Static Public Member Functions

static UaDateTime now ()
 Returns a UaDateTime object representing the current date and time. More...
 
static UaDateTime fromString (const UaString &)
 Get UaDateTime from string in ISO 8601 format. More...
 
static UaDateTime fromTime_t (time_t tim)
 Get UaDateTime from time_t. More...
 

Friends

UABASE_EXPORT UaDataStream & operator<< (UaDataStream &, const UaDateTime &)
 Writes the internal date/time value to the stream.
 
UABASE_EXPORT UaDataStream & operator>> (UaDataStream &, UaDateTime &)
 Reads a date/time value from the stream.
 

Detailed Description

Wrapper class for the UA stack structure OpcUa_DateTime.

Helper class for handling the OPC UA built-in data type DateTime. It provides conversion and comparison functions and allows to create a current timestamp.

A DateTime value is a 64-bit signed integer which represents the number of 100 nanosecond intervals since January 1, 1601 (UTC). It is normally represented by the structure OpcUa_DateTime with the two UInt32 members dwLowDateTime and dwHighDateTime. This may be different on special platforms.

Not all platforms will be able to represent the full range of dates and times that can be represented with this built-in data type. For example, the UNIX time_t structure only has a 1 second resolution and cannot represent dates prior to 1970. For this reason, a number of rules shall be applied when dealing with date/time values that exceed the dynamic range of a platform. These rules are:

  • A DateTime value is 0 if either the value is equal to or earlier than 1601-01-01 12:00AM or the value is the earliest date that can be represented within the platform.
  • A DateTime value is the maximum Int64 value if either the value is equal to or greater than 9999-01-01 11:59:59PM or the value is the latest date/time that can be represented within the platform.
  • A value is the earliest time on the platform if either the DateTime value is 0 or the DateTime value represents a time earlier than the earliest time that can be represented within the platform.
  • A value is the latest time on the platform if either the DateTime is the maximum value for an Int64 or the DateTime represents a time later than the latest time that can be represented within the platform.

These rules imply that the earliest and latest times that can be represented on a given platform are invalid date/time values and should be treated that way by applications.

Constructor & Destructor Documentation

UaDateTime::UaDateTime ( const OpcUa_DateTime dateTime)

Creates a UaDateTime object initialized with the passed OpcUa_DateTime structure.

Parameters
dateTimethe OpcUa_DateTime structure used to initialize the UaDateTime object
UaDateTime::UaDateTime ( const FILETIME &  fileTime)

Creates a UaDateTime object initialized with the passed Windows FILETIME value.

This constructor is only available on Windows.

Parameters
fileTimeThe initial date time as FILETIME.
UaDateTime::UaDateTime ( const OpcUa_Int64 &  time)

Creates a UaDateTime object initialized with the passed Int64 value.

Parameters
timeThe time as OpcUa_Int64.

Member Function Documentation

void UaDateTime::addMilliSecs ( int  msecs)

Adds the passed number of milliseconds to the date/time value.

Parameters
msecsthe number of milliseconds to add.
void UaDateTime::addSecs ( int  secs)

Adds the passed number of seconds to the date/time value.

Parameters
secsthe number of seconds to add.
OpcUa_Int32 UaDateTime::daysTo ( const UaDateTime to) const

Returns the days from the own time value to the passed time value.

Calculates the days between the value of the UaDateTime object and the passed UaDateTime object. If the passed in time is later than the internal time, the return value is positive. If the passed in value is earlier than the internal time, the returned value is negative.

Parameters
tothe UaDateTime used to calculate difference in days.
Returns
the difference in days between the internal value and the passed in value.
UaDateTime UaDateTime::fromString ( const UaString sTime)
static

Get UaDateTime from string in ISO 8601 format.

UaDateTime myTime;
UaString sTime("2012-05-30T09:30:10Z");
myTime = UaDateTime::fromString(sTime);

ISO 8601 string format is specified in the following form "YYYY-MM-DDThh:mm:ss" where:

Placeholder Description
YYYY indicates the year
MM indicates the month
DD indicates the day
T indicates the start of the required time section
hh indicates the hour
mm indicates the minute
ss indicates the second

Example: 2002-05-30T09:00:00

Note
All components are required!

Time Zones:
To specify a time zone, you can either enter a dateTime in UTC time by adding a "Z" behind the time: 2012-05-30T09:30:10Z
or you can specify an offset from the UTC time by adding a positive or negative time behind the time: 2012-05-30T09:30:10-06:00 or 2012-05-30T09:30:10+06:00

Parameters
sTimethe string to convert.
Returns
UaDateTime object initialized from the string.
UaDateTime UaDateTime::fromTime_t ( time_t  tim)
static

Get UaDateTime from time_t.

UaDateTime myTime;
time_t tt = 1393398000; // Wed, 26 Feb 2014 07:00:00 GMT
Parameters
timthe time_t struct used to initialize the UaDateTime object
Returns
UaDateTime object initialized from time_t.
OpcUa_Boolean UaDateTime::isNull ( ) const

Checks whether UaDateTime is null or not.

Returns
true if null, false if not.
int UaDateTime::msec ( ) const

Returns the milliseconds part of the UaDateTime object.

Returns
the milliseconds part of this dateTime.
OpcUa_Int64 UaDateTime::msecsTo ( const UaDateTime to) const

Returns the milliseconds from the own time value to the passed time value.

Calculates the milliseconds between the value of the UaDateTime object and the passed UaDateTime object. If the passed in time is later than the internal time, the return value is positive. If the passed in value is earlier than the internal time, the returned value is negative.

Parameters
tothe UaDateTime used to calculate the difference in milliseconds.
Returns
the difference in milliseconds between the internal value and the passed in value.
UaDateTime UaDateTime::now ( )
static

Returns a UaDateTime object representing the current date and time.

UaDateTime currentTime;
currentTime = UaDateTime::now();
Returns
the date and the time of now.
UaDateTime::operator FILETIME ( ) const

Get the time as Windows FILETIME value.

This operator is only available on Windows.

Returns
the time as Windows FILETIME.
UaDateTime::operator OpcUa_DateTime ( ) const

Get the time as OpcUa_DateTime structure.

Returns
the UaDateTime.
UaDateTime::operator OpcUa_Int64 ( ) const

Get the time as Int64 value.

Returns
the OpcUa_Int64.
bool UaDateTime::operator!= ( const UaDateTime other) const

Not Equals operator for comparing two date/time values.

See also
operator==
Parameters
otherthe UaDateTime to compare.
Returns
true if other is not equal to this.
bool UaDateTime::operator< ( const UaDateTime other) const

Less than operator for comparing two date/time values.

Parameters
otherthe UaDateTime to compare.
Returns
true if time of the object is earlier than other, false if not.
UaDateTime & UaDateTime::operator= ( const FILETIME &  fileTime)

Assign a new time using Windows FILETIME value.

This operator is only available on Windows.

Parameters
fileTimeThe time as FILETIME.
Returns
the date time object.
UaDateTime & UaDateTime::operator= ( const OpcUa_Int64 &  time)

Assign a new time using a OpcUa_Int64 value.

Parameters
timeThe time as OpcUa_Int64.
Returns
the date time.
bool UaDateTime::operator== ( const UaDateTime other) const

Equals operator for comparing two date/time values.

Parameters
otherthe UaDateTime to compare.
Returns
true if other equals this, false if not.
bool UaDateTime::operator> ( const UaDateTime other) const

Greater than operator for comparing two date/time values.

Parameters
otherthe UaDateTime to compare.
Returns
true if time of the object is later than other, false if not.
OpcUa_Int32 UaDateTime::secsTo ( const UaDateTime to) const

Returns the seconds from the own time value to the passed time value.

Calculates the seconds between the value of the UaDateTime object and the passed UaDateTime object. If the passed in time is later than the internal time, the return value is positive. If the passed in value is earlier than the internal time, the returned value is negative.

Parameters
tothe UaDateTime used to calculate difference in seconds.
Returns
the difference in seconds between the internal value and the passed in value.
void UaDateTime::toDataValue ( UaDataValue dataValue,
OpcUa_Boolean  updateTimeStamps 
) const

Copies the internal date/time value to a UaDataValue.

The value is set with the date/time and the status is set to OpcUa_Good.

Parameters
dataValuethe UaDataValue to update.
updateTimeStampsIf OpcUa_True, the timestamps of the DataValue are set to the current time. Otherwise the timestamps are not changed.
void UaDateTime::toDataValue ( OpcUa_DataValue dataValue,
OpcUa_Boolean  updateTimeStamps 
) const

Copies the internal date/time value to a OpcUa_DataValue structure.

The value is set with the date/time and the status is set to OpcUa_Good.

Parameters
dataValuethe UaDataValue to update.
updateTimeStampsIf OpcUa_True, the timestamps of the DataValue are set to the current time. Otherwise the timestamps are initialized to null.
UaString UaDateTime::toDateString ( ) const

Converts the date part of the UaDateTime into a UaString.

See also
fromString for a description of the string format.
Returns
UaDateTime value date part converted to a string.
UaString UaDateTime::toString ( ) const

Converts the UaDateTime into a UaString.

See also
fromString for a description of the string format.
Returns
UaDateTime value converted to a string.
time_t UaDateTime::toTime_t ( ) const

Converts the UaDateTime value to UNIX timestamp format time_t.

Note
This format only has a precision of seconds. The milliseconds part will be cut.

The time range is different as well and goes from 1970-01-01 till 2038-01-18 on 32 bit systems.

Returns
UaDateTime value in UNIX timestamp format time_t.
UaString UaDateTime::toTimeString ( ) const

Converts the time part of the UaDateTime into a UaString.

See also
fromString for a description of the string format.
Returns
UaDateTime value time part converted to a string.

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