I have searched Google and StackOverflow, and have found tangential discussions, but nothing that addresses this: Is there any standard or commonly used C++ type to hold a timestamp that corresponds to (local time, offset from UTC)?

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

Preferably, I'd hope for something that correctly handles comparisons and deltas, and already has conversion to/from ISO 8601.

Notes:

  • Whatever their benefits, using POSIX-type time zones are not an option. The systems we interact with, using medical industry standard interfaces, provide either timestamps either as an unspecified local time or as (local time, offset from UTC). They simply do not provide full time zone information.

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

  • time_point in boost and C++11 is lovely, but I can't see how to apply it to this problem, at least not without an unwieldy proliferation of clocks (or epochs). But, I'm open to guidance on how it can.

The fallback is to roll our own, but I can't believe that we're the first to face this question.

有帮助吗?

解决方案

Instead of storing local time and TZ offset, use boost::local_date_time and store UTC and the TZ offset. It works out to exactly the same thing and has already been rolled for you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top