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;

In reply to Date::Calc and and daylight savings time by marek1703

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.