High Performance OPC UA Server SDK  1.1.0.158
ua_datetime

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

Macros

#define ua_datetime_copy(dst, src)   *(dst) = *(src)
 

Typedefs

typedef uint64_t ua_datetime
 Opaque ua_datetime. More...
 

Functions

void ua_datetime_init (ua_datetime *dt)
 Initialize ua_datetime with the earliest possible value.
 
void ua_datetime_clear (ua_datetime *dt)
 Clear ua_datetime and set to the earliest possible value.
 
int ua_datetime_compare (const ua_datetime *a, const ua_datetime *b)
 Compare two ua_datetimes. More...
 
int ua_datetime_now (ua_datetime *dt)
 Get the current time as ua_datetime. More...
 
time_t ua_datetime_to_time_t (const ua_datetime *dt)
 Convert ua_datetime to time_t. More...
 
void ua_datetime_from_time_t (ua_datetime *dt, const time_t *t)
 Convert time_t to ua_datetime. More...
 
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...
 
int ua_datetime_snprintf (char *dst, size_t size, const ua_datetime *dt)
 Converts the given UA datetime parameter dt into a string. More...
 
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

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

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.
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.
void ua_datetime_from_time_t ( ua_datetime dt,
const time_t *  t 
)

Convert time_t to ua_datetime.

Parameters
dtResult of the conversion.
tValue to convert.
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.
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.

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.
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:

1 ua_datetime dt;
2 struct ua_string date;
3 
4 if (ua_datetime_now(&dt) == 0) {
5  ua_datetime_to_string(&dt, &date);
6  printf("now = %s\n", ua_string_const_data(&date));
7  ua_string_clear(&date);
8 }
Parameters
dtThe UA datetime value
dstThe UA string which receives the result.
Returns
Zero on success, a negative error code on failure.
time_t ua_datetime_to_time_t ( const ua_datetime dt)

Convert ua_datetime to time_t.

Parameters
dtValue to convert.
Returns
Result of the conversion.