in reply to Date::Calc and and daylight savings time

Hi marek,

This piece of code seems to work fine on my linux box, except for item: 391263207 => "Sonntag, 26.05.2013 - 13:13:27". Could you run it on more data?

#!/usr/bin/perl use warnings; use strict; use Date::Calc qw(Day_of_Week Day_of_Week_to_Text); use Time::Local; my %date_pairs = ( 391263207 => "Sonntag, 26.05.2013 - 13:13:27", 410000659 => "Sonntag, 29.12.2013 - 10:04:19", 410891318 => "Mittwoch, 08.01.2014 - 17:28:38", 412528640 => "Montag, 27.01.2014 - 16:17:20", 413028709 => "Sonntag, 02.02.2014 - 11:11:49", 414241970 => "Sonntag, 16.02.2014 - 12:12:50", 433494560 => "Samstag, 27.09.2014 - 09:09:20" ); $ENV{TZ} = 'Europe/Berlin'; # sec,min,hours,day,month,year my $epoch = timegm(0, 0, 0, 1, 0, 70); my $macep = timegm(0, 0, 0, 1, 0, 101); print "$epoch -- $macep\n"; foreach my $key ( sort keys %date_pairs ) { # 0 1 2 3 4 5 6 7 8 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localti +me($key+$macep); $mon++; $year += 1900; my $dstr = Day_of_Week_to_Text(Day_of_Week($year, $mon, $mday), 3) +; my $datestr = sprintf("%-8s %02d.%02d.%02d %02d:%02d:%02d %d", $ds +tr, $mday, $mon, $year, $hour, $min, $sec, $isdst); print "$key - $date_pairs{$key} -- $datestr\n"; }
Output:
0 -- 978307200 391263207 - Sonntag, 26.05.2013 - 13:13:27 -- Sonntag 26.05.2013 14: +13:27 1 410000659 - Sonntag, 29.12.2013 - 10:04:19 -- Sonntag 29.12.2013 10: +04:19 0 410891318 - Mittwoch, 08.01.2014 - 17:28:38 -- Mittwoch 08.01.2014 17: +28:38 0 412528640 - Montag, 27.01.2014 - 16:17:20 -- Montag 27.01.2014 16: +17:20 0 413028709 - Sonntag, 02.02.2014 - 11:11:49 -- Sonntag 02.02.2014 11: +11:49 0 414241970 - Sonntag, 16.02.2014 - 12:12:50 -- Sonntag 16.02.2014 12: +12:50 0 433494560 - Samstag, 27.09.2014 - 09:09:20 -- Samstag 27.09.2014 09: +09:20 1
Regards

Replies are listed 'Best First'.
Re^2: Date::Calc and and daylight savings time
by marek1703 (Acolyte) on Jan 01, 2015 at 15:38 UTC

    Great! The New Year 2015 starts really fantastic! :-)
    I am so grateful for your answer. Strange, that apparently we have to mix up two Modules (Date::Calc and Time::Local) to get it right.

    I have to read the manual of Time::Local to fully understand your answer.
    Funny that the first timestamp (391265355) gets the wrong daylight savings time.
    One moment: May is far into the daylight saving time == 1 ... So it is right. Probably my expected date is wrong hmmmm

    I will try to find an answer on myself.

    Thank you again :-)

    marek