#include <inttypes.h>
#include <stdbool.h>
#include <stddef.h>
#include <time.h>
#include "sopc_builtintypes.h"
#include "sopc_enums.h"
Go to the source code of this file.
|
struct | SOPC_tm |
| S2OPC equivalent of standard struct tm. Fields use fix-length numerical values. More...
|
|
|
typedef time_t | SOPC_Unix_Time |
|
typedef struct SOPC_tm | SOPC_tm |
| S2OPC equivalent of standard struct tm. Fields use fix-length numerical values.
|
|
|
SOPC_DateTime | SOPC_Time_GetCurrentTimeUTC (void) |
| return the current time in DateTime format which is 100 nanoseconds from 1601/01/01 00:00:00 UTC
|
|
char * | SOPC_Time_GetString (SOPC_DateTime time, bool local, bool compact) |
| returns a C string representation of the given time in DateTime format E.g.:
|
|
char * | SOPC_Time_GetStringOfCurrentLocalTime (bool compact) |
| return the current local time as a C String, e.g.:
|
|
char * | SOPC_Time_GetStringOfCurrentTimeUTC (bool compact) |
| return the current UTC time as a C String, e.g.:
|
|
SOPC_ReturnStatus | SOPC_Time_Breakdown_Local (SOPC_Unix_Time t, struct tm *tm) |
| Breaks down a timestamp to its structured representation in local time.
|
|
SOPC_ReturnStatus | SOPC_Time_Breakdown_UTC (SOPC_Unix_Time t, struct tm *tm) |
| Breaks down a timestamp to its structured representation in UTC time.
|
|
SOPC_ReturnStatus | SOPC_Time_FromUnixTime (SOPC_Unix_Time time, SOPC_DateTime *res) |
| Converts a UNIX timestamp to a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC.
|
|
SOPC_ReturnStatus | SOPC_Time_ToUnixTime (SOPC_DateTime dt, SOPC_Unix_Time *res) |
| Converts a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC to a UNIX timestamp.
|
|
bool | SOPC_tm_FromXsdDateTime (const char *datetime, size_t len, SOPC_tm *tm) |
| Parse a string containing an XSD format datetime '[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]', it might be followed by 'Z' to indicate UTC timezone or '+/-[hh]:[mm]' for an offset of UTC. See https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#dateTime, the equivalent regular expression is: -?([1-9][0-9]{3,}|0[0-9]{3}) -(0[1-9]|1[0-2]) -(0[1-9]|[12][0-9]|3[01]) T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?|(24:00:00(.0+)?)) (Z|(+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?
|
|
SOPC_ReturnStatus | SOPC_Time_FromXsdDateTime (const char *dateTime, size_t len, int64_t *res) |
| Converts a string using XSD DateTime format (see SOPC_tm_FromXsdDateTime) to a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC.
|
|
◆ SOPC_Unix_Time
A time reference in UNIX standard representation (number of seconds since Jan 1st, 1970)
◆ SOPC_tm
typedef struct SOPC_tm SOPC_tm |
S2OPC equivalent of standard struct tm. Fields use fix-length numerical values.
◆ SOPC_Time_GetCurrentTimeUTC()
return the current time in DateTime format which is 100 nanoseconds from 1601/01/01 00:00:00 UTC
Note: since the clock is not monotonic, it should not be used to measure elapsed time
- Returns
- the current time in DateTime format
◆ SOPC_Time_GetString()
char * SOPC_Time_GetString |
( |
SOPC_DateTime | time, |
|
|
bool | local, |
|
|
bool | compact ) |
returns a C string representation of the given time in DateTime format E.g.:
- compact == false: "2018/01/30 13:15:52.694\0"
- compact == true: "20180130_131552_694\0"
- Parameters
-
time | time value in DataTime format, which is 100 nanoseconds from 1601/01/01 00:00:00 UTC |
local | provides local time if set, UTC time otherwise |
compact | provides compact version when flag is set |
- Returns
- A new allocated representation of time. Must be freed by caller with
SOPC_Free
◆ SOPC_Time_GetStringOfCurrentLocalTime()
char * SOPC_Time_GetStringOfCurrentLocalTime |
( |
bool | compact | ) |
|
return the current local time as a C String, e.g.:
- compact == false: "2018/01/30 13:15:52.694\0"
- compact == true: "20180130_131552_694\0"
- Parameters
-
compact | provides compact version when flag is set |
- Returns
- the current local time as C string (to be deallocated after use)
◆ SOPC_Time_GetStringOfCurrentTimeUTC()
char * SOPC_Time_GetStringOfCurrentTimeUTC |
( |
bool | compact | ) |
|
return the current UTC time as a C String, e.g.:
- compact == false: "2018/01/30 13:15:52.694\0"
- compact == true: "20180130_131552_694\0"
- Parameters
-
compact | provides compact version when flag is set |
- Returns
- the current UTC time as C string (to be deallocated after use)
◆ SOPC_Time_Breakdown_Local()
Breaks down a timestamp to its structured representation in local time.
- Parameters
-
t | the timestamp. |
tm | the structured representation of the timestamp in local time. |
- Returns
- SOPC_STATUS_OK in case of success, SOPC_STATUS_NOK in case of error.
◆ SOPC_Time_Breakdown_UTC()
Breaks down a timestamp to its structured representation in UTC time.
- Parameters
-
t | the timestamp. |
tm | the structured representation of the timestamp in UTC time. |
- Returns
- SOPC_STATUS_OK in case of success, SOPC_STATUS_NOK in case of error.
◆ SOPC_Time_FromUnixTime()
Converts a UNIX timestamp to a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC.
- Parameters
-
time | the UNIX timestamp |
res | the resulting time |
- Returns
- SOPC_STATUS_OK on success, an error code on failure
◆ SOPC_Time_ToUnixTime()
Converts a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC to a UNIX timestamp.
- Parameters
-
dt | the input time |
res | the resulting time_t |
- Returns
- SOPC_STATUS_OK on success, an error code on failure
◆ SOPC_tm_FromXsdDateTime()
bool SOPC_tm_FromXsdDateTime |
( |
const char * | datetime, |
|
|
size_t | len, |
|
|
SOPC_tm * | tm ) |
Parse a string containing an XSD format datetime '[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]', it might be followed by 'Z' to indicate UTC timezone or '+/-[hh]:[mm]' for an offset of UTC. See https://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/datatypes.html#dateTime, the equivalent regular expression is: -?([1-9][0-9]{3,}|0[0-9]{3}) -(0[1-9]|1[0-2]) -(0[1-9]|[12][0-9]|3[01]) T(([01][0-9]|2[0-3]):[0-5][0-9]:[0-5]0-9?|(24:00:00(.0+)?)) (Z|(+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))?
- Note
- Output NULL pointers are not set and do not lead to return function failure
- Parameters
-
datetime | The string containing a XSD datetime value to parse |
len | The length of the the string (strlen(datetime) if datetime is a C string) |
tm | Pointer to broken-down time structure used as output parameter. It is filled in case of success. |
- Returns
- Returns true if the datetime parsing succeeded and
len
characters parsed, false otherwise
◆ SOPC_Time_FromXsdDateTime()
SOPC_ReturnStatus SOPC_Time_FromXsdDateTime |
( |
const char * | dateTime, |
|
|
size_t | len, |
|
|
int64_t * | res ) |
Converts a string using XSD DateTime format (see SOPC_tm_FromXsdDateTime) to a time expressed in 100ns slices since 1601/01/01 00:00:00 UTC.
- Warning
- This function uses similar limitation as indicated for encoding for OPC UA binary DateTime (see part 6):
- A date/time value is encoded as 0 if the year is earlier than 1601
- A date/time is encoded as the maximum value for an Int64 if the year is greater than 9999 Since those values cannot be encoded as indicated by OPC UA standard, there is no need to manage converting those.
-
This function considers leap days but not leap seconds since it is not requested by OPC UA specification (see part 3 and 6). It means each day is considered to be 86400 seconds without considering any leap seconds.
- Parameters
-
dateTime | The string containing a XSD datetime value to parse |
len | The length of the the string (strlen(datetime) if datetime is a C string) |
res | The resulting time |
- Returns
- SOPC_STATUS_OK on success, an error code on failure