Boost logo

Boost Users :

Subject: Re: [Boost-users] [date_time] dst_local_start_time
From: Jean-Pierre Bergamin (james_at_[hidden])
Date: 2008-11-06 02:39:14


Hello

We ended up with an explanation like this as well. But in my opinion,
2:00 in summertime does not exist, since 2:00 is 3:00. I'd expect that
the function dst_local_start_time returns a local_date_time of
2007-Mar-25 03:00:00.

As you say, some functions with local_date_times behave very "unnatural"
and counterintuitive. Does it make sense to file a bug-report?

Regards

James

> forgot to write some kind of conclusion after my code sample:
>
> My guess: The dst_local_start_time() function returns a ptime object
> which actually represents wall time at the location (Zurich in your
> case).
>
> I would say that 2007-Mar-25 02:00:00 is the start of the DST just
> like 2007-Mar-25 03:00:00, because those two times are exactly the
> same. It's not like "when the clock reaches 02:00, we've reached end
> of wintertime, then we switch to 03:00 and have beginning of
> summertime". On that day, in the infinitesimal time interval when it
> is 02:00, it is also 03:00.
>
> So, personally, I would say, the confusing part is that local times
> are represented by ptimes in some cases (see also the example I sent).
> The result is OK, though.
>
> If you look at the dst_local_end_time(), it is consistent with the
> start function: In both cases, it returns the time which would be
> shown on the clock without the switch.
>
>
> Regards,
>
> Roland
>
>
> Roland Bock wrote:
>> Hi,
>>
>> I had a similar problem in getting the current wall time in New York.
>> I wrote the following working function and added a bunch of comments,
>> since the library is counter-intuitive here IMHO:
>>
>>
>> // Get local time of day, based on time zone
>> const boost::posix_time::time_duration
>> DateTime::localizedTimeOfDayAsDuration(const
>> boost::local_time::time_zone_ptr timeZone)
>> {
>> /* This looks a bit perverted (and it is in my eyes :-))
>>
>> Calling time_of_day on a local_date_time object implicitly
>> turns it into a UTC ptime object first, thus yielding UTC time_of_day
>> instead of the wall time (I do not really understand why it works
>> this way, but it does).
>>
>> Calling local_time on a local_date_time object returns a ptime
>> object which in this case represents wall time within the given time
>> zone (again, I don't know why the behavior is this way, but it is).
>> */
>> return
>> local_microsec_clock::local_time(timeZone).local_time().time_of_day();
>> }
>>
>> Please let me know if that helped or if you found a better
>> solution/explanation.
>>
>> Regards,
>>
>> Roland
>>
>> Jean-Pierre Bergamin wrote:
>>> Hello
>>>
>>> I'm confused about the returned time of the dst_local_start_time()
>>> function. First of all I don't understand why a ptime is returned
>>> and not a local_date_time, buy anyway.
>>>
>>> The ptime I get returned for the timezone Europe/Zurich for 2007 is:
>>> 2007-Mar-25 02:00:00
>>> Assuming that this is a UTC time, the local time in Zurich would
>>> then be 2007-Mar-25 04:00:00 (because during summertime, Zurich is
>>> 2h ahead of UTC), but the correct local dst start time would be
>>> 2007-Mar-25 03:00:00 (because the clocks are shifted from 2 to 3).
>>> To correctly calculate the dst start time, I have to add the
>>> dst_offset to the returned time_of_day.
>>>
>>> The returned ptime 2007-Mar-25 02:00:00 seems to be the endtime of
>>> wintertime as a local time.
>>>
>>> time_zone_ptr zh_tz = tz_db.time_zone_from_region("Europe/Zurich");
>>> ptime zh_dst_start_time = zh_tz->dst_local_start_time(2007);
>>> std::cout << zh_dst_start_time << std::endl; // 2007-Mar-25 02:00:00
>>> local_date_time zh_dst_local_start_time =
>>> local_date_time(zh_dst_start_time, zh_tz);
>>> std::cout << zh_dst_local_start_time << std::endl; // 2007-Mar-25
>>> 04:00:00 CEST which is wrong!
>>>
>>> ptime zh_dst_start_time_ok = zh_dst_start_time + zh_tz->dst_offset();
>>> local_date_time zh_dst_local_start_time_ok =
>>> local_date_time(zh_dst_start_time_ok.date(),
>>> zh_dst_start_time_ok.time_of_day(), zh_tz, true);
>>> std::cout << zh_dst_local_start_time_ok << std::endl; // 2007-Mar-25
>>> 03:00:00 CEST which is correct
>>>
>>> So what time exactly is local_start_time() returning?
>>> Is this a bug or am I missing something?
>>>
>>>
>>> Regards
>>>
>>> James
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net