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 https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html 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().

 

Am I missing something fundamentally, or what?

 

Regards

 

Mats Webjörn

 

Webjörn IngenjörsKonsult AB

Solhemsbackarna 75A

SE-163 56 SPÅNGA

Sweden