epoch1970;585664 Wrote: 
> Gordon, thanks for doing the right thing. Once more.
The code relies on Time::Zone;


Code:
--------------------
    
  sub IsDSTChangePending {
        my ($nStartDate, $nEndDate) = @_;
  
        my ($sec1,$min1,$hour1,$mday1,$mon1,$year1,$wday1,$yday1,$isdst1) = 
localtime($nStartDate);
        my ($sec2,$min2,$hour2,$mday2,$mon2,$year2,$wday2,$yday2,$isdst2) = 
localtime($nEndDate);
  
        if ($isdst1 != $isdst2) {
                $g{log}->is_debug && $g{log}->debug ( "DST change is pending! 
$nStartDate isDST: $isdst1 vs. $nEndDate isDST: $isdst2");
                if ($isdst2) {
                        return 1;       #Spring ahead..
                } else {
                        return -1;      #Fall back...
                }
        }
        return 0;
  }
  
--------------------

..used thusly:


Code:
--------------------
    
        # Adjust for daylight savings time change...should only happen twice a 
year..
        $bNeedDSTAdjustment = IsDSTChangePending($nCurTime, $nRTCWakeupTime);
  
        if ($bNeedDSTAdjustment > 0) {
                #Spring ahead...so night is 1 hour shorter, so wake up an hour 
earlier..
                $g{log}->is_debug && $g{log}->debug ( "Spring ahead: adjusting 
wakeup time to an hour earlier..");
                $nRTCWakeupTime -= 3600;
        } elsif ($bNeedDSTAdjustment < 0) {
                #Fall back...night is 1 hour longer, so wake up an hour later..
  
                #If the next alarm is between 24 hours and 23 hours in the 
future..
                #..schedule wakeup for today instead.
                if ( ($nRTCWakeupTime <= ($nCurTime + 86400)) &&
                     ($nRTCWakeupTime >  ($nCurTime + 82800)) ) {
                        $nRTCWakeupTime -= 86400;
                }
  
                $g{log}->is_debug && $g{log}->debug ( "Fall Back: adjusting 
wakeup time to an hour later..");
                $nRTCWakeupTime += 3600;
        }
  
  
--------------------

There's lot's of assumptions made there about the nature of a
Summer/Winter time change.  It's assumed that the change will be one
hour and that it follows the "springs ahead, falls back" convention. 
If the "tea party" candidates win big here in the states next Tuesday,
I'm sure I'll need to modify that code to account for non-hour
incremental changes and "fall-ahead, spring back" switches...i.e. there
will be a need to accommodate a higher ambient level of irrationality in
(what for now) is civil time-keeping.  I.e., I don't think we'll be able
to count on there being much "civil" left in public regulation.


-- 
gharris999
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=48521

_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins

Reply via email to