High Performance OPC UA Server SDK  1.7.1.383

This Built-in DataType defines a Gregorian calendar date. More...

Typedefs

typedef uint64_t ua_datetime
 Opaque ua_datetime. More...
 

Functions

BASE_EXPORT void ua_datetime_init (ua_datetime *dt)
 Initialize ua_datetime with the earliest possible value.
 
BASE_EXPORT void ua_datetime_clear (ua_datetime *dt)
 Clear ua_datetime and set to the earliest possible value.
 
BASE_EXPORT int ua_datetime_compare (const ua_datetime *a, const ua_datetime *b)
 Compare two ua_datetimes. More...
 
BASE_EXPORT int ua_datetime_now (ua_datetime *dt)
 Get the current time as ua_datetime. More...
 
static void ua_datetime_copy (ua_datetime *dst, const ua_datetime *src)
 
BASE_EXPORT time_t ua_datetime_to_time_t (const ua_datetime *dt)
 Convert ua_datetime to time_t. More...
 
BASE_EXPORT uint64_t ua_datetime_to_time_t64 (const ua_datetime *dt)
 Convert ua_datetime to time_t. More...
 
BASE_EXPORT uint64_t ua_datetime_msecs_since_epoch (const ua_datetime *dt)
 Returns the milliseconds since UNIX epoch (1970-01-01T00:00:00Z). More...
 
BASE_EXPORT void ua_datetime_from_time_t (ua_datetime *dt, const time_t *t)
 Convert time_t to ua_datetime. More...
 
BASE_EXPORT int ua_datetime_to_string (const ua_datetime *dt, struct ua_string *dst)
 Converts the given UA datetime parameter dt into an UA string. More...
 
BASE_EXPORT int ua_datetime_snprintf (char *dst, size_t size, const ua_datetime *dt)
 Converts the given UA datetime parameter dt into a string. More...
 
BASE_EXPORT int ua_datetime_from_string (ua_datetime *dt, const struct ua_string *src)
 Parses the given date string and creates a UA datetime from it. More...
 

Detailed Description

This Built-in DataType defines a Gregorian calendar date.

It is 64-bit signed integer representing the number of 100 nanoseconds intervals since 1601-01-01 00:00:00. This is the same as the WIN32 FILETIME type.

See also
util_utctime

Typedef Documentation

◆ ua_datetime

typedef uint64_t ua_datetime

Opaque ua_datetime.

Opaque means that you cannot make any assumption if the type's contents. So don't access any fields directly. Always used the provided accessor functions.

Function Documentation

◆ ua_datetime_compare()

BASE_EXPORT int ua_datetime_compare ( const ua_datetime a,
const ua_datetime b 
)

Compare two ua_datetimes.

Returns
Zero if the ua_datetimes are the same.

◆ ua_datetime_from_string()

BASE_EXPORT int ua_datetime_from_string ( ua_datetime dt,
const struct ua_string src 
)

Parses the given date string and creates a UA datetime from it.

This function expects a date string in ISO8601 format: "YYYY-MM-DDThh:mm:ss[.nnn]Z". This is the same format as used in ua_datetime_snprintf and ua_datetime_to_string, so this works as reverse operation of ua_datetime_to_string. The milliseconds part nnn is optional. Currently only Zulu time is supported.

Parameters
dtUA DateTime which receives the resulting date value
srcDate string to parse.
Returns
Zero on success. UA_EBAD if the operation fails.

◆ ua_datetime_from_time_t()

BASE_EXPORT void ua_datetime_from_time_t ( ua_datetime dt,
const time_t *  t 
)

Convert time_t to ua_datetime.

Note the a time_t (UNIX epoch) has a different time range then UA DateTime (Windows FILETIME). The UNIX epoch starts at 1970, wherees FILETIME starts at 1601.

In UA some specific DateTime values have a special meaning. For this reason the following exceptions exist:

  • The first time_t value (0 = 1970-01-01T00:00:00Z) is converted to the first DateTime value (0 = 1601-01-01T00:00:00Z).
  • The max time_t value is converted to INT64_MAX.
  • negative time_t values are not supported.

UA specification 6 section 5.2.2.5 DateTime:

A date/time value is encoded as 0 if either 1) The value is equal to or earlier than 1601-01-01 12:00AM UTC. 2) The value is the earliest date that can be represented with the DevelopmentPlatform’s encoding.

A date/time is encoded as the maximum value for an Int64 if either 3) The value is equal to or greater than 9999-12-31 11:59:59PM UTC, 4) The value is the latest date that can be represented with the DevelopmentPlatform’s encoding.

Parameters
dtResult of the conversion.
tValue to convert.

◆ ua_datetime_msecs_since_epoch()

BASE_EXPORT uint64_t ua_datetime_msecs_since_epoch ( const ua_datetime dt)

Returns the milliseconds since UNIX epoch (1970-01-01T00:00:00Z).

Parameters
dtThe UA datetime value to convert.
Returns
Milliseconds.

◆ ua_datetime_now()

BASE_EXPORT int ua_datetime_now ( ua_datetime dt)

Get the current time as ua_datetime.

Parameters
dtPointer to ua_datetime to write the current time to.
Returns
Zero on success or errorcode on failure.

◆ ua_datetime_snprintf()

BASE_EXPORT int ua_datetime_snprintf ( char *  dst,
size_t  size,
const ua_datetime dt 
)

Converts the given UA datetime parameter dt into a string.

This functions prints the date string into the preallocated buffer dst. The date format is "YYYY-MM-DDThh:mm:ss.nnnZ", also known as ISO8601. The fractional part at the end is optional (n) and has an accuracy of up to 7 digits to be able to represent the full UA DateTime resolution (100ns intervals). Examples: 2020-02-04T00:00:00Z 2017-05-26T15:42:00.1934169Z 2020-02-12T13:22:47.785Z

Parameters
dstPointer of preallocated string buffer.
sizeLength of dst in bytes.
dtUA DateTime input parameter.
Returns
Zero on success. UA_EBADTRUNCATED if the provided buffer was too short.

◆ ua_datetime_to_string()

BASE_EXPORT int ua_datetime_to_string ( const ua_datetime dt,
struct ua_string dst 
)

Converts the given UA datetime parameter dt into an UA string.

This function uses ua_datetime_snprintf to write the formatted date string into the UA string buffer. The parameter dst, can be an uninitialized variable. It will be initialized using ua_string_allocate internally. You must call ua_string_clear to free these resources.

Example:

struct ua_string date;
if (ua_datetime_now(&dt) == 0) {
ua_datetime_to_string(&dt, &date);
printf("now = %s\n", ua_string_const_data(&date));
}
Parameters
dtThe UA datetime value
dstThe UA string which receives the result.
Returns
Zero on success, a negative error code on failure.

◆ ua_datetime_to_time_t()

BASE_EXPORT time_t ua_datetime_to_time_t ( const ua_datetime dt)

Convert ua_datetime to time_t.

Note the a time_t (UNIX epoch) has a different time range then UA DateTime (Windows FILETIME). The UNIX epoch starts at 1970, wherees FILETIME starts at 1601.

In UA some specific DateTime values have a special meaning. For this reason the following exceptions exist:

  • DateTime values before 1970-01-01T00:00:00Z will be converted to time_t = 0.
  • DateTime values after 2038-01-19T03:14:07Z will be converted to time_t = 2147483647 (INT32_MAX). This is the 32bit time_t limit (Y2038 problem).
    See also
    ua_datetime_to_time_t64.
    Parameters
    dtValue to convert.
    Returns
    Result of the conversion.

◆ ua_datetime_to_time_t64()

BASE_EXPORT uint64_t ua_datetime_to_time_t64 ( const ua_datetime dt)

Convert ua_datetime to time_t.

This allows to create 64 bit time_t values on systems where time_t is defined as a 32bit type. This is e.g. the case on 32 bit Linux systems, whereas on 64 bit Linux this type is also 64 bit and does not have the Y2038 problem.

In UA some specific DateTime values have a special meaning. For this reason the following exceptions exist:

  • DateTime values before 1970-01-01T00:00:00Z will be converted to time_t = 0.
  • The latest allowed DateTime value is 9999-12-31 11:59:59PM UTC, if the value is larger it will be truncated to INT64_MAX.
Parameters
dtValue to convert.
Returns
Result of the conversion (64bit).