Dear Perl Mongers,<div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">I just encountered the problem that I needed Central European Time (for timestamps etc.) on a server located in the USA.</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">Anybody can easily verify that the rules for daylight savings time are much less predictable in the USA than in Central Europe (last Sunday in March at 2:00 => DST, last Sunday in October at 3:00 => winter time).</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">There are times when the USA are in DST but not Central Europe, and vice-versa.</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">This could therefore be a real challenge to calculate.</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">However, we make two observations: firstly, every Un*x server knows GMT. Secondly, coincidentally the switch-over times in Europe for going to DST and back are always at GMT 1:00.</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">Now with Date::Calc to the rescue, we ask the server to give us GMT (and let him handle the idiosyncracies of the US-American DST rules) and calculate whether we are between the last Sunday in March at 1:00 GMT and the last Sunday in October at 1:00 GMT, and add 1 or 2 hours (for CET=GMT+1 or CEST=GMT+2, according to DST or not).</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">Voila!</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">The subroutine that does this is relatively simple:</div><div id="yMail_cursorElementTracker_0.7730735444929451"><div id="yMail_cursorElementTracker_0.9171999541576952"><pre style="widows: 1; word-wrap: break-word; white-space: pre-wrap;" id="yMail_cursorElementTracker_0.23624590341933072">use Date::Calc qw(:all);</pre><pre style="widows: 1; word-wrap: break-word; white-space: pre-wrap;" id="yMail_cursorElementTracker_0.23624590341933072">sub Central_European_Time<br></pre><pre style="widows: 1; word-wrap: break-word; white-space: pre-wrap;" id="yMail_cursorElementTracker_0.23624590341933072">{
    my(@Now)  = Gmtime();
    my($year) = $Now[0];
    my(@DST,@CET);
    @DST = Nth_Weekday_of_Month_Year($year, 3,7,4) unless (@DST = Nth_Weekday_of_Month_Year($year, 3,7,5));
    @CET = Nth_Weekday_of_Month_Year($year,10,7,4) unless (@CET = Nth_Weekday_of_Month_Year($year,10,7,5));
    my $now = (((Day_of_Year(@Now[0,1,2])-1) * 24 + $Now[3]) * 60 + $Now[4]) * 60 + $Now[5];
    my $dst =  ((Day_of_Year(@DST)       -1) * 24 + 1) * 3600;
    my $cet =  ((Day_of_Year(@CET)       -1) * 24 + 1) * 3600;
    if (($dst <= $now) and ($now < $cet)) { return(Add_Delta_YMDHMS(@Now[0,1,2,3,4,5],0,0,0,2,0,0)); }
    else                                  { return(Add_Delta_YMDHMS(@Now[0,1,2,3,4,5],0,0,0,1,0,0)); }
}</pre></div></div><div id="yMail_cursorElementTracker_0.7730735444929451">It returns a list of the form ($year, $month,$day,$hour,$min,$sec).</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">See also <a data-yahoo-extracted-link="true" href="http://sb.fluomedia.org/scripts/time_pl" id="yMail_cursorElementTracker_0.6614032019861042">http://sb.fluomedia.org/scripts/time_pl</a></div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">I hope you like it! :-)</div><div id="yMail_cursorElementTracker_0.7730735444929451"><br></div><div id="yMail_cursorElementTracker_0.7730735444929451">Cheers,</div><div id="yMail_cursorElementTracker_0.7730735444929451">Steffen</div>