Boost C++ Libraries: Ticket #3336: utc offset calculated wrong https://svn.boost.org/trac10/ticket/3336 <p> Boost seems to invert the posix time zone specs or even worse to calculate them completely wrong: </p> <p> <a class="ext-link" href="http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html"><span class="icon">​</span>http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html</a> </p> <p> states: </p> <p> "If preceded by a '-', the timezone shall be east of the Prime Meridian; otherwise, it shall be west (which may be indicated by an optional preceding '+' )." </p> <p> Using the following lines in a c++ program: </p> <pre class="wiki"> time_zone_ptr myzone(new posix_time_zone(string("CET-1CEST,M3.5.0,M10.5.0/3"))); // e.g. Europe/Berlin cout &lt;&lt; "Posix time string: " &lt;&lt; myzone-&gt;to_posix_string() &lt;&lt; endl; local_date_time mylocaltime(date(2009,8,11), time_duration(17,0,0), myzone, true); cout &lt;&lt; "Wall clock: " &lt;&lt; mylocaltime.local_time() &lt;&lt; endl; cout &lt;&lt; "Time in UTC: " &lt;&lt; mylocaltime.utc_time() &lt;&lt; endl; </pre><p> gives following output: <br /> Posix time string: CET-01CEST+01,M3.5.0/02:00,M10.5.0/03:00 <br /> Wall clock: 2009-Aug-11 17:00:00 <br /> Time in UTC: 2009-Aug-11 17:00:00 <br /> </p> <p> The system I used: Debian GNU/Linux squeeze/sid <br /> uname -a<br /> Linux fafner 2.6.28.7 <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> SMP Mon Mar 16 17:39:15 CET 2009 i686 GNU/Linux </p> <p> output from date:<br /> date -d "2009-8-11 17:00 CEST "<br /> Di 11. Aug 17:00:00 CEST 2009<br /> date -d "2009-8-11 17:00 CEST " -u<br /> Di 11. Aug 15:00:00 UTC 2009 </p> <p> Libraries (debian): libboost-date-time1.38.0 libboost-date-time1.38-dev libboost-date-time-dev </p> <p> The time zone spec ist taken from /usr/share/zoneinfo/CET on my system. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3336 Trac 1.4.3 Steven Watanabe Tue, 11 Aug 2009 18:59:02 GMT component changed; owner set https://svn.boost.org/trac10/ticket/3336#comment:1 https://svn.boost.org/trac10/ticket/3336#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">az_sw_dude</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">date_time</span> </li> </ul> Ticket Jason Pettiss <jpettiss@…> Tue, 27 Apr 2010 15:42:04 GMT <link>https://svn.boost.org/trac10/ticket/3336#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3336#comment:2</guid> <description> <p> The UTC offset in POSIX 1003.1 section 8.3 TZ strings is inverted from that in Olson TZ database strings, which is a cause for confusion. The former treats UTC as relative to the local time, i.e what do we add to the <em>local</em> wall clock to produce the wall clock time in UTC. The latter treats the local time as relative to UTC, as in, what do we add to the time in UTC to get to the local time. </p> <p> The man pages for tzset(3) seem pretty consistent although some are clearer than others. I like this wording best, myself: </p> <dl class="wiki"><dt>offset</dt><dd>Indicates the value one must add to the local time to arrive at Coordinated Universal Time. </dd></dl> <p> Sun is their own celestial body but they see it the same way: </p> <p> <a class="ext-link" href="http://docs.sun.com/source/816-5523-10/appf.htm"><span class="icon">​</span>http://docs.sun.com/source/816-5523-10/appf.htm</a> </p> <table class="wiki"> <tr><td style="text-align: left">USA (Eastern) </td><td style="text-align: left">EST5EDT </td></tr><tr><td style="text-align: left">Russia (Moscow) </td><td style="text-align: left">MST-3MDT </td></tr></table> <p> Here also, positive is west of Greenwich, negative is east of it. </p> <p> As a hacky workaround, the string can be manipulated prior to feeding it to posix_time_zone. Find the first [0-9+-]. If we're not at the end of the string, if '+' change to '-' and vice versa. Otherwise insert '-' before the current position. Something like the following (untested!): </p> <pre class="wiki">void fliptzoffset(std::string&amp; tzstr) { std::string::iterator i = tzstr.begin(), e = tzstr.end(); while (i != e &amp;&amp; !isdigit(*i) &amp;&amp; '+'!=*i &amp;&amp; '-'!=*i) ++i; if (i == e) return; if ('-' == *i) *i = '+'; else if ('+' == *i) *i = '-'; else tzstr.insert(i, '-'); } </pre> </description> <category>Ticket</category> </item> <item> <author>roman.fietze@…</author> <pubDate>Tue, 27 Nov 2012 14:11:51 GMT</pubDate> <title>version changed https://svn.boost.org/trac10/ticket/3336#comment:3 https://svn.boost.org/trac10/ticket/3336#comment:3 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.38.0</span> → <span class="trac-field-new">Boost 1.44.0</span> </li> </ul> <p> This bug doesn't seem to get a lot of attention. </p> <p> It is still valid for newer versions of the boost library. </p> Ticket Alexey Spiridonov <bstbg.20.lesha@…> Sun, 19 Jan 2014 11:18:14 GMT <link>https://svn.boost.org/trac10/ticket/3336#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3336#comment:4</guid> <description> <p> Just got bitten by the same bug. Correct behavior: </p> <pre class="wiki">$ export TZ="PST-8PDT,M3.2.0,M11.1.0"; date -d@1383465600 Sun Nov 3 16:00:00 PST 2013 </pre><p> posix_time_zone maps the same timestamp with the same timezone string to "Sun Nov 3 01:00:00 PST 2013" (16 hours - 1 DST adjustment). Here's another (currently working) link to the POSIX RFC that boost::local_time purports to implement: </p> <p> <a class="ext-link" href="http://tools.ietf.org/html/draft-ietf-dhc-timezone-01"><span class="icon">​</span>http://tools.ietf.org/html/draft-ietf-dhc-timezone-01</a> </p> <p> The relevant text is at the end of page 2, beginning of page 3. </p> <p> The boost::local_time documentation and code are both written assuming "-" means "west of Greenwich" and "+" means "east of Greenwich", but the standard clearly states otherwise. </p> <p> Flipping the sign is pretty easy (I can send a patch, even), but I'm not sure what's Boost's preferred approach for fixing such errors. The flip would break code that depends on the currently broken behavior. </p> <p> If it's not appropriate to fix the bug in the current API, posix_time_zone2 might be introduced that has the correct sign. Does anybody see other approaches? </p> </description> <category>Ticket</category> </item> <item> <author>Alexey Spiridonov <bstbg.20.lesha@…></author> <pubDate>Sun, 19 Jan 2014 11:31:50 GMT</pubDate> <title>version, milestone changed https://svn.boost.org/trac10/ticket/3336#comment:5 https://svn.boost.org/trac10/ticket/3336#comment:5 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">Boost 1.54.0</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> <p> I reproduced it in 1.51 and 1.54. </p> Ticket