Daylight Savings using timelocal() and localtime()

Discussion in 'Perl Misc' started by Datamon, Mar 12, 2007.

  1. Datamon

    Datamon Guest

    When I run the script below on a windoze 2000 desktop with the latest
    ms dst patch, I get:

    D>dstest.pl 060301
    060301 IS NOT in DLS
    # which is correct

    D>dstest.pl 060401
    060401 IS in DLS
    # which is WRONG (060402 was the start of DLS last year, so 060401 was
    prior to DLS).

    It looks like msoft changed the 'first Sunday in April' (old rule) to
    'second Sunday in March' (new rule) for ALL years...

    I have a solution if anyone is interested.

    (file saved as dstest.pl)
    #!/usr/bin/perl -w

    use strict;
    use Time::Local;

    my ($stdate, $indls);

    $stdate = shift;
    if ( ! defined $stdate ) {
    print "Enter a date string as YYMMDD: ";
    $stdate = <>;
    }
    chomp ( $stdate );
    $indls = InDls ( $stdate );
    printf "%s %s in DLS\n", $stdate, $indls ? "IS" : "IS NOT";

    exit;

    #------------------------------------------------------------------------------
    # This routine determines if NOON on YYMMDD is in DLS
    # I suspect it uses an ms function or dll as it's functionality
    changed
    # after implementing the recent ms DLS patch...
    sub InDls {
    my ( $yymmdd ) = @_;
    die "$yymmdd is an invalid date!\n" if ( length ( $yymmdd ) !=
    6 );
    my ($yy, $mm, $dd) = unpack ( "a2 a2 a2", $yymmdd );
    my @ts = ( 0, 0, 12, $dd, $mm-1, $yy );
    my $nt = timelocal ( @ts ); # convert to seconds since epoch
    @ts = localtime ( $nt ); # convert back to components
    return ( $ts[8] ); # return 'Is DST' (9th element)
    } # InDls
    Datamon, Mar 12, 2007
    #1
    1. Advertising

  2. Datamon

    Guest

    , Mar 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Ternier
    Replies:
    1
    Views:
    1,458
    Ryan Ternier
    Oct 14, 2005
  2. John Taylor
    Replies:
    2
    Views:
    478
    Mark Tolonen
    Apr 12, 2004
  3. Qvx
    Replies:
    3
    Views:
    364
    Nick Coghlan
    Jan 29, 2005
  4. J Moreno
    Replies:
    14
    Views:
    242
    J Moreno
    Mar 9, 2006
  5. John
    Replies:
    2
    Views:
    103
Loading...

Share This Page