There is no obvious timestamp with a timezone offset type for C ++. Roll our own?

I searched Google and StackOverflow and found tangential discussions, but nothing that addresses this: is there any standard or commonly used C ++ type to store the timestamp corresponding to (local time, offset from UTC)?

This date format conforms to ISO 8601, System.DateTimeOffset in .NET, and TIMESTAMP WITH TIME ZONE in several database systems.

It is advisable that I hope that it handles comparisons and delta correctly, and already has a conversion to / from ISO 8601.

Notes:

  • Regardless of their benefits, using POSIX time zones is not an option. The systems we interact with using standard medical industry interfaces provide either timestamps, either as an undefined local time, or as (local time, offset from UTC). They simply do not provide complete time zone information.

  • Converting everyone to UTC is also not an option. Local time, from the point of view of the system that recorded time, is an important piece of information that we cannot lose.

  • time_point in boost and C ++ 11 is great, but I don’t see how to apply it to this problem, at least not without the cumbersome distribution of clocks (or eras). But I am open to guidance on how this is possible.

Rollback is to collapse our own, but I cannot believe that we were the first to encounter this issue.

+4
source share
1 answer

Instead of saving local time and TZ offset use boost::local_date_time and keep UTC and TZ offset. It works the same way and has already been rolled up for you.

+1
source

Source: https://habr.com/ru/post/1484518/


All Articles