Daylight Savings using timelocal() and localtime()

D

Datamon

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top