> This occurs on the 23th hour in the fall and the 0th hour in the spring.
This program shows a brute force way
> to find these that might convince you [1].


Slick! I'm convinced.  Hmm, so if you need it to be ever accurate (and want
to stay w/ localtime() you need to track changes in the DST field,
something like:
my  ($isdst) = ( localtime() ) [8];

 my ($mday, $mon, $year, $prev_isdst) = (localtime(time - 60 * 60 * 24) )[
3,4,5, 8];
 printf("%d/%02d/%02d\n", $year + 1900, $mon + 1,
   $isdst == $prev_isdst ? $mday
   : $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
   : (localtime($t - 60 * 60 * 25) )[ 3]
  );

Probably won't convince you [2] but ....

a

[1]
$h = 60 * 60;
$end = time + 366 * 24 * $h;

for ($t = time; $t < $end; $t += 0.5 * $h) {
    print scalar(localtime($t)), "\n" if day($t) eq day($t + $h) && day($t
- 24 * $h) ne day($t + $h - 24 * $h);
}

sub day {
    my($y, $m, $d) = (localtime shift)[5,4,3];
    $y += 1900;
    $m += 1;
    return sprintf "%04d-%02d-%02d", $y, $m, $d;
}

[2]
#!/usr/bin/perl
my $h = 60 * 60;
my $end = time + 366 * 24 * $h;

my $cur_isdst;
for (my $t = time; $t < $end; $t += 0.1 * $h) {
 #  0    1    2     3     4    5     6     7     8
   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t);

 my ($mday, $mon, $year, $prev_isdst) = (localtime($t - 60 * 60 * 24) )[
3,4,5, 8];
 printf("%d/%02d/%02d - cur: %s -24: %s -23: %s\n", $year + 1900, $mon + 1,
   $isdst == $prev_isdst ? $mday
   : $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
   : (localtime($t - 60 * 60 * 25) )[ 3]
   ,    scalar(localtime($t)) ,
   day($t + $h) , day($t - 24 * $h),  day($t + $h - 24 * $h) )
if day($t) eq day($t + $h) && day($t - 24 * $h) ne day($t + $h - 24 * $h);

#    print scalar(localtime($t)), "\n" if day($t) eq day($t + $h) && day($t
- 24 * $h) ne day($t + $h - 24 * $h);
}

sub day {
    my($y, $m, $d) = (localtime shift)[5,4,3];
    $y += 1900;
    $m += 1;
    return sprintf "%04d-%02d-%02d", $y, $m, $d;
}
-------------------
Andy Bach
Systems Mangler
Internet: [EMAIL PROTECTED]
Voice: (608) 261-5738 Fax: 264-5932

When I retire, I'm going to spend my evenings by the fireplace, going
through those boxes.  There are things in there that ought to be burned.
Richard Millhouse Nixon (Parade magazine)

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to