marek1703 has asked for the wisdom of the Perl Monks concerning the following question:
Hallo dear Perl Monks!
I wish you a happy new Year 2015! Hoping you will share your wisdom as you did last year.
I have a huge file of SMS Messages (Macintosh) where I need to transform the timestamps into human readable dates. I did not captured well, how to calculate the daylight savings ...
While copying and pasting many many SMS into my file to make a perl script working on it, I am very proud of my poor programming skills, until there is a message popping up claiming to be sent at 12:12 - but the calculated time is 11:12 :-(
Here my example script. Thank you for your insight!
marek
#! /usr/bin/perl # I am trying to convert the seconds of the sms database into a # reasonable date. # But there is a problem left: the daylight saving time (Sommerzeit vs + Winterzeit) use warnings; use strict; use Date::Calc qw(Localtime Day_of_Week Day_of_Week_to_Text); 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" ); foreach my $key ( keys %date_pairs ) { print "="x130; my $timestamp = $key; my ($year,$month,$day, $hour,$min,$sec, $doy,$dow,$dst) = Localtime($timestamp); print "\nOriginal Vars:\nTimestamp is: $timestamp\nYear: $year, Mo +nth: $month, Day: $day, Hour: $hour, Minutes: $min, Seconds: $sec, Da +y of Year: $doy, Day of Week: $dow, Daylight saving: $dst \n","_"x130 +,"\n"; $year += 31; $dow = Day_of_Week($year,$month,$day); my $lang = 3; # this is for German language my $dow_name = Day_of_Week_to_Text($dow,$lang); my $calculated_date = sprintf "%s, %02s.%02s.%d - %02s:%02s:%02s", + $dow_name, $day, $month, $year, $hour, $min, $sec; print "Transformed Vars:\nYear: $year, Month: $month, Day: $day, H +our: $hour, Minutes: $min, Seconds: $sec, Day of Year: $doy, Day of W +eek: $dow, Daylight saving: $dst \nCalculated Date:\t$calculated_date +\nExpected Date:\t\t$date_pairs{$key}\n"; } print "="x130;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Date::Calc and and daylight savings time
by Anonymous Monk on Jan 01, 2015 at 11:11 UTC | |
by marek1703 (Acolyte) on Jan 01, 2015 at 11:30 UTC | |
by Corion (Patriarch) on Jan 01, 2015 at 11:39 UTC | |
|
Re: Date::Calc and and daylight savings time
by pme (Monsignor) on Jan 01, 2015 at 14:06 UTC | |
by marek1703 (Acolyte) on Jan 01, 2015 at 15:38 UTC | |
|
Re: Date::Calc and and daylight savings time
by Anonymous Monk on Jan 01, 2015 at 15:31 UTC |