26 using UaDuration = std::chrono::duration<int64_t, std::ratio<1, 10'000'000>>;
30 template <
typename Clock,
typename Duration>
31 DateTime(std::chrono::time_point<Clock, Duration> timePoint)
40 template <
typename Clock,
typename Duration>
44 std::chrono::duration_cast<UaDuration>(timePoint.time_since_epoch()).count()
50 return DateTime(UA_DateTime_fromUnixTime(unixTime));
59 template <
typename Clock = DefaultClock,
typename Duration = UaDuration>
60 std::chrono::time_point<Clock, Duration>
toTimePoint()
const {
61 const std::chrono::time_point<Clock, Duration> unixEpoch{};
66 return unixEpoch + std::chrono::duration_cast<Duration>(sinceEpoch);
74 return UA_DateTime_toUnixTime(
get());
83 int64_t
get() const noexcept {
89 std::string
format(std::string_view
format,
bool localtime =
false)
const;
UA_DateTime wrapper class.
int64_t get() const noexcept
Get DateTime value as 100 nanosecond intervals since January 1, 1601 (UTC).
UA_DateTimeStruct toStruct() const noexcept
Convert to UA_DateTimeStruct.
static DateTime fromUnixTime(int64_t unixTime) noexcept
Get DateTime from Unix time.
static DateTime now() noexcept
Get current DateTime.
std::chrono::duration< int64_t, std::ratio< 1, 10 '000 '000 > > UaDuration
static DateTime fromTimePoint(std::chrono::time_point< Clock, Duration > timePoint)
Get DateTime from std::chrono::time_point.
int64_t toUnixTime() const noexcept
Convert to Unix time (number of seconds since January 1, 1970 UTC).
static int64_t localTimeUtcOffset() noexcept
Offset of local time to UTC.
DateTime(std::chrono::time_point< Clock, Duration > timePoint)
std::string format(std::string_view format, bool localtime=false) const
Convert to string with given format (same format codes as strftime).
std::chrono::time_point< Clock, Duration > toTimePoint() const
Convert to std::chrono::time_point.
std::chrono::system_clock DefaultClock
Template base class to wrap UA_* type objects.
constexpr TypeWrapper()=default
constexpr T * handle() noexcept
Return pointer to native object.
#define UA_DATETIME_UNIX_EPOCH
UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime t)
UA_DateTime UA_DateTime_now(void)
UA_Int64 UA_DateTime_localTimeUtcOffset(void)