Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Daylight Savings using timelocal() and localtime()

Reply
Thread Tools

Daylight Savings using timelocal() and localtime()

 
 
Datamon
Guest
Posts: n/a
 
      03-12-2007
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

 
Reply With Quote
 
 
 
 
rmts9@hotmail.com
Guest
Posts: n/a
 
      03-14-2007


The problem is a dll that works incorrectly when the TZ variable is
set see
http://support.microsoft.com/kb/932590
of course there is no hot fix for win2k

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with DateTime and TimeZones / DayLight savings time Ryan Ternier ASP .Net 1 10-14-2005 05:20 PM
datetime and daylight savings problem James Python 1 10-11-2005 08:43 PM
New worm and daylight savings? Ray Wesley Kinserlow Jr. Computer Information 6 08-29-2005 06:32 PM
Daylight savings and getmtime Qvx Python 3 01-29-2005 04:45 AM
Problem with dates and daylight savings... John Taylor Python 2 04-12-2004 05:31 PM



Advertisments