[datetime] local_date_time and time zone issues
I've been playing with local_date_time and time zones but don't understand the return values of utc_time(), local_time() and local_time_in(). Here's a small program: ---------- #include <boost/date_time/local_time/local_time.hpp> #include <iostream> int main() { boost::local_time::time_zone_ptr tz1(new boost::local_time::posix_time_zone("CET+1")); boost::posix_time::ptime pt1(boost::gregorian::date(2009, 1, 5), boost::posix_time::time_duration(12, 0, 0)); boost::local_time::local_date_time dt1(pt1, tz1); std::cout << dt1.utc_time() << std::endl; std::cout << dt1.local_time() << std::endl; boost::local_time::time_zone_ptr tz2(new boost::local_time::posix_time_zone("CET+2")); std::cout << dt1.local_time_in(tz2) << std::endl; } ---------- The output of this program is: 2009-Jan-05 12:00:00 2009-Jan-05 13:00:00 2009-Jan-05 14:00:00 CET The program uses CET which is the abbreviation for Central European Time which is UTC+1. If the UTC time is now 12:00:00 the local time in CET+1 must be 14:00:00 (and not 13:00:00). Accordingly the local time in CET+2 must be 15:00:00. Why Boost.DateTime appends "CET" to the local time in CET+2 I don't understand either. Is this a bug or do I misunderstand these functions? Boris
AMDG Boris wrote:
The program uses CET which is the abbreviation for Central European Time which is UTC+1. If the UTC time is now 12:00:00 the local time in CET+1 must be 14:00:00 (and not 13:00:00). Accordingly the local time in CET+2 must be 15:00:00. Why Boost.DateTime appends "CET" to the local time in CET+2 I don't understand either.
From http://www.boost.org/doc/html/date_time/local_time.html#date_time.local_time... 'offset' is the offset from UTC.
In Christ, Steven Watanabe
Hi, you also should change your last line to std::cout << dt1.local_time_in(tz2).local_time() << std::endl; Regards, Roland Steven Watanabe wrote:
AMDG
Boris wrote:
The program uses CET which is the abbreviation for Central European Time which is UTC+1. If the UTC time is now 12:00:00 the local time in CET+1 must be 14:00:00 (and not 13:00:00). Accordingly the local time in CET+2 must be 15:00:00. Why Boost.DateTime appends "CET" to the local time in CET+2 I don't understand either.
From http://www.boost.org/doc/html/date_time/local_time.html#date_time.local_time...
'offset' is the offset from UTC.
In Christ, Steven Watanabe
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Calling local_time on a local_date_time object returns a ptime object which represents wall time within the given time zone. See also http://lists.boost.org/boost-users/2008/11/41946.php Regards, Roland Boris wrote:
On Wed, 07 Jan 2009 19:26:01 +0100, Roland Bock <rbock@eudoxos.de> wrote:
Hi,
you also should change your last line to
std::cout << dt1.local_time_in(tz2).local_time() << std::endl;
Is this a work-around to drop the CET from the output or is there a good reason? :)
Boris
[...]
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wed, 07 Jan 2009 19:16:46 +0100, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG
Boris wrote:
The program uses CET which is the abbreviation for Central European Time which is UTC+1. If the UTC time is now 12:00:00 the local time in CET+1 must be 14:00:00 (and not 13:00:00). Accordingly the local time in CET+2 must be 15:00:00. Why Boost.DateTime appends "CET" to the local time in CET+2 I don't understand either.
From http://www.boost.org/doc/html/date_time/local_time.html#date_time.local_time... 'offset' is the offset from UTC.
Thanks, I missed this. CET doesn't have any measning then (at least not in my example)? Boris
participants (3)
-
Boris
-
Roland Bock
-
Steven Watanabe