perl DateTime and non-existent time user input because of DST clock forward -


in scenario know timezone of user , date time input user in textbox (i.e. calendar user selects date types time), after parsed , know hours , minutes, how should deal wih non-existent time because of dst clock forward (eg. 02:00 not exist because of clocks turned forward 1 hour) in order pass -at least existent hour- datetime->new();?

use datetime; $dt = datetime->new(     year   => $year_userinput,  #2016     month  => $month_userinput,  #03     day    => $day_userinput,  #27     hour   => $hour_userinput,  #02     minute => $minute_userinput,  #30     second => 0,     time_zone => $timezone_userinput,  #europe/berlin ); 

error: invalid local time date in time zone: europe/berlin

as go daylight savings, there's no problem. assuming dls starts @ 2am on given day in fictitious time zone, atz (a timezone) offset of n hrs, 3 seconds commencing 1 second before 2am timestamped;

1:59:59 atz +n 3:00:00 adz +(n+1) 3:00:01 adz +(n+1) 

...and when coming out of daylight savings ...

2:00:00 adz +(n+1) 2:00:01 adz +(n+1) ... ... hour later ... 2:59:59 adz +(n+1) 2:00:00 atz +n 2:00:01 atz 

there appears have been earlier "2:00:01" included offset of (n+1) - or in timezone adz - whereas 1 in atz (n). datetime module raises issue this:

ambiguous local times

because of daylight saving time, possible specify local time ambiguous. example, in in 2003, transition saving standard time occurred on october 26, @ 02:00:00 local time. local clock changed 01:59:59 (saving time) 01:00:00 (standard time). means hour 01:00:00 through 01:59:59 occurs twice, though utc time continues move forward.

to avoid issue, going have include timezone or offset when creating time objects. that, need use date (you said had it) detect end-of-dls day and, if user has chosen time within critical hour, you're going have prompt "is 2:30am adz or 2:30am atz?" or similar. likewise, if it's start-of-dls, interface has refuse entries referencing critical hour.

earlier in doco datetime, there's suggestion - performance reasons - of determining local timezone once , using throughout app;

our $app::localtz = datetime::timezone->new( name => 'local' );  ... # everywhere else  $dt = datetime->new( ..., time_zone => $app::localtz ); 

... going leave vulnerable issue again. since interface going have know start-of-dls day or end-of-dls day, can set , use $app::localtz advised , override specific, prompted-for timezone if it's end-of-dls day.


Comments