Boost logo

Boost Users :

Subject: Re: [Boost-users] Question on Posix timezone string
From: Leon Mlakar (leon_at_[hidden])
Date: 2018-12-28 22:25:47

On 28.12.2018 22:30, Mats Webjörn/WIKAB wrote:
> Hi Leon,
> Yes, but the problem is that the offset for Berlin in Boost
> date_time_zonespec.csv is +01, not -01
Yeah, I got that, just wanted to confirm that you read the Posix docs

I tried your code with older Boost (1.62) on my Mac and got the same
string you put in comment (CET+01CEST+01,M3.5.0/02:00,M10.5.0/03:00) and
if I feed this string to my TZ, for sure the output of date command is
two hours off.

It seems that to_posix_string() is broken. I think that the author of
the library may have incorrectly interpreted the standard; unfortunately
I don't have a copy of ISO/IEC 9945-1 at hand so I can't confirm that.
But a quick Internet search for examples shows strings such as
PST8PDT7,M4.1.0/2:00:00,M10.5.0/2:00:00 (US/Pacific), which indicate
that the timezones west of GMT have positive offsets, which also means
that Central Europe should have negative offsets. Also, the Boost
states (Introduction, near the top):

     'std' specifies the abbrev of the time zone. 'offset' is the offset
from UTC

Which would explain the incorrect signs ... in Posix it's the other way
around, the offset is really the offset of UTC from the local time.

Of course, all that will not help you, the results will still be
incorrect. The only course of action I can recommend is to check what
exactly ISO/IEC 9945-1 states, and if above is correct, fill a bug
report at Boost. Unfortunately I can't think of any short term solution,
other than looking for a different library.



> nMats
> *Från:*Boost-users [mailto:boost-users-bounces_at_[hidden]] *För
> *Leon Mlakar via Boost-users
> *Skickat:* den 28 december 2018 22:18
> *Till:* boost-users_at_[hidden]
> *Kopia:* Leon Mlakar
> *Ämne:* Re: [Boost-users] Question on Posix timezone string
> On 28.12.2018 21:34, Mats Webjörn/WIKAB via Boost-users wrote:
> I’m using Boost 1.66 and use the following code to get a Posix
> string to set my uCLinux TZ environment variable to get a local
> time from an UTC time
> #include <boost/date_time/local_time/tz_database.hpp>
> #include <boost/date_time/local_time/local_time.hpp>
> tz_database tz_db;
> tz_db.load_from_file("./date_time_zonespec.csv");
> time_zone_ptr nyc = tz_db.time_zone_from_region("Europe/Stockholm");
> auto s = nyc->to_posix_string();  //
> "CET+01CEST+01,M3.5.0/02:00,M10.5.0/03:00"
> setenv("TZ", s.c_str(), 1);
> The odd thing is that my localtime becomes incorrect, and is
> actually 1 hr wrong on the opposite side of UTC.
> But, when I read
> it says
> “The offset specifies the time value you must *_add to the local
> time_* to get a Coordinated Universal Time value”.
> Not add to UTC time, which seems like the Boost Posix string
> assumes !!!!!
> Which explains why 16:00 UTC give 15:00 CET instead of 17:00 which
> is the correct value, when using localtime_r().
> I think this document is correct, and that POSIX systems actually add
> the TZ offset to the displayed local time to yield UTC, unlike to ISO
> 8601 where offset is subtracted from the local time (or, change the
> sign of the offset, then add :-) in the time string, to get the UTC .
> Five minutes past noon on one winter day in Berlin would thus be
> 12:05:00 with TZ offset -01 on Posix system and 12:05:00+01 in ISO
> 8601 textual presentation.
> Cheers,
> Leon

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at