to_posix_string() returns invalid timezone string

Open
#94 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
localization

Research direction

Start by reproducing the reported snippet with tz_database, Europe/Stockholm, and to_posix_string(). Then inspect the implementation of to_posix_string() and any related timezone tests to determine which POSIX offset convention is used. Done means the generated TZ string produces the correct Stockholm-versus-UTC conversion under the stated environment.

Written by the indexing model from the issue text.

Description

The following code
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(); setenv("TZ", s.c_str(), 1);
will set TZ to "CET+01CEST+01,M3.5.0/02:00,M10.5.0/03:00" which will cause Stockholm local time to be 10:00:00 when UTC(GMT/London) time is 11:00:00 which clearly is incorrect.

ANSI/IEEE Std 1003.1 section 8.3 Other Environment Variables reads for TZ variable

Offset Indicates the value added to the local time to arrive at Coordinated Universal Time

gnu.org reads the same
It also says regarding offset

This is positive if the local time zone is west of the Prime Meridian and negative if it is east.

But Boost 1.69 date-time says

A posix_time_zone is unique in that the object is created from a Posix time zone string (IEEE Std 1003.1). A POSIX time zone string takes the form of:
"std offset dst [offset],start[/time],end[/time]" (w/no spaces).
'std' specifies the abbrev of the time zone. 'offset' is the offset from UTC.
"PST-8PDT01:00:00,M4.1.0/02:00:00,M10.1.0/02:00:00"
"PST-8PDT,M4.1.0,M10.1.0"
These two are actually the same specification (defaults were used in the second string). This zone lies eight hours west of GMT …”

If I add -8 to a PST local time I will NOT get GMT=UTC time!! It seems like somewhere here (most likely in to_posix_string()) is a huge bug since the Posix/GNU and Boost interpretation of the Posix timezone strings contradict each other.

Dominant language
C++
Stars
70
Forks
99
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/date_time

All issues in boostorg/date_time

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.