gnork has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

how do I find out if daylight saving is in effect for a certain date?

Date::Calc offers the ability to find out if daylight saving is active at system time, but I didnt find a way to check this for a specific date.

One could set the system time to the date in question and check scalar System_Clock > 0, but this doesnt sound very clever.
I dont want to reinvent the wheel if I dont have to, so any hint is appreciated.
Update: Formatting

TIA Gnork


cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
errors->(c)

Replies are listed 'Best First'.
Re: Daylight Saving
by Aragorn (Curate) on Apr 07, 2004 at 11:32 UTC
    Create a time value for using with localtime with the function timelocal from the (standard) Time::Local module.
    #!/usr/bin/perl use strict; use warnings; use Time::Local; my $time = timelocal(0, 0, 0, 1, 3, 104); # create time value my $time_str = localtime($time); # textual time representation my ($dst) = (localtime($time))[8]; # fetch daylight savings time flag if ($dst) { print "Daylight savings in effect on $time_str\n"; } else { print "Daylight savings time not in effect on $time_str\n"; }
    The above example determines the DST for April 1, 2004. Changing the "create time value" statement to my $time = timelocal(0, 0, 0, 1, 1, 104);, it determines the DST for January 1, 2004.

    Arjen

Re: Daylight Saving
by eserte (Deacon) on Apr 07, 2004 at 11:26 UTC
    Check for the last element in the return value of localtime.
Re: Daylight Saving
by gnork (Scribe) on Apr 07, 2004 at 11:58 UTC
    I didn't check localtime close enough, I guess. Sometimes one needs that swift kick from outside ...

    Problem solved, case closed ...

    Thanks,
    Jan

    cat /dev/world | perl -e "(/(^.*? \?) 42\!/) && (print $1))"
    errors->(c)
Re: Daylight Saving
by tbone1 (Monsignor) on Apr 07, 2004 at 12:44 UTC
    Also sprach gnork:

    how do I find out if daylight saving is in effect for a certain date?

    (WARNING: SMART-ALECK RESPONSE TO FOLLOW)

    Moving to Arizona, Hawaii, or Indiana makes this problem trivial.

    --
    tbone1, YAPS (Yet Another Perl Schlub)
    And remember, if he succeeds, so what.
    - Chick McGee

      Most parts of Arizona, and most parts of Indiana.

      Of course, there is a similar concept in other parts of the world, and the rules on what date the timeshift happens vary too. For example, southern hemisphere countries shift the opposite way, as Santa Claus has to wear a much cooler outfit down there.

      --
      [ e d @ h a l l e y . c c ]

        An interesting note about Arizona:
        In Arizona, many Indian reservations DO switch to daylight saving time, while the rest of the state does NOT. For example, the Navajo Reservation DOES switch to daylight saving time, but the Hopi reservation, located in the middle of it, DOES NOT.
        -scienceworld.wolfram.com

        -enlil

      Howdy!

      ...depends on where in Indiana... :)

      yours,
      Michael
Re: Daylight Saving
by hossman (Prior) on Apr 08, 2004 at 06:54 UTC
    Date::Calc offers the ability to find out if daylight saving is active at system time, but I didnt find a way to check this for a specific date.

    It looks like you didn't read Date::Calc's perldoc very carefully.

    In addition to the System_Clock funtion you describe, the functions Gmtime, Localtime, and Timezone all return a "$dst" value as well -- and unlike System_Clock, the other three all take an optional [time] parameter, to indicate which datetime you are interested in.