Bug 10842 - getNextAlarm reports incorrect value if DST change is pending..
: getNextAlarm reports incorrect value if DST change is pending..
Status: RESOLVED WONTFIX
Product: Logitech Media Server
Classification: Unclassified
Component: Alarm
: 7.3.3
: All All
: -- minor (vote)
: Future
Assigned To: Unassigned bug - please assign me!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-01-27 09:37 UTC by Gordon Harris
Modified: 2009-03-04 14:12 UTC (History)
3 users (show)

See Also:
Category: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Harris 2009-01-27 09:37:39 UTC
For system locales that incorporate biannual DST (daylight savings time) changes, the Slim::Utils::Alarm->getNextAlarm($client, 1) function returns an incorrect value when called in instances where there is a DST time change pending between the call and the alarm.

Example:

-->Time zone is MST (Mountain Standard Time, aka Americas/Denver).

-->System time is 09-03-08 01:59:24 (just before 2AM, March 3rd, 2009).

-->Player Alarm in the UI is set for 6:00 AM.

getNextAlarm($client) returns 1236517224, ie Sun, 08 Mar 2009 13:00:24 UTC, which is an INCORRECT value.

Now, 1 minute later..

-->System time is 09-03-08 03:00:24 (ie 1 minute later and after the OS "springs ahead" the system time to 3:00 AM).

getNextAlarm($client) returns 1236513624, ie Sun, 08 Mar 2009 12:00:24 UTC, which is the correct value.

getNextAlarm should always return the SAME epoch date, no matter when the call is made.  As it stands now, getNextAlarm returns the alarm epoch date valid for the time the function is called, not for the actual time of the alarm.

A "IsDSTChangePending()" function needs to be added to make getNextAlarm "DST change aware".
Comment 1 Gordon Harris 2009-01-27 09:44:08 UTC
Reports if a DST change is pending between two times:

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}->debug ( "DST change is pending! $nStartDate isDST: $isdst1 vs. $nEndDate isDST: $isdst2\n");
		if ($isdst2) {
			return 1;	#Spring ahead..assumes that $nEndDate > $nStartDate
		} else {
			return -1;	#Fall back...
		}
	}
	return 0;                       #No change pending..
}
Comment 2 Max Spicer 2009-01-27 11:57:26 UTC
Slim::Utils::getNextAlarm() returns an alarm object, not the time of the next alarm.  Could you provide a bit more detail about what you're trying to do?
Comment 3 Gordon Harris 2009-01-27 12:39:05 UTC
Yes...I see your point.  Perhaps my problem is really with findNextTime()

I'm trying to get the epoch date/time of the next alarm that SC will try to service.  Here is how I'm doing it:

my $nNextAlarmTime = 0;
my $szNextAlarmClient = "";

foreach my $curClient (Slim::Player::Client::clients()) {
	$curAlarm = Slim::Utils::Alarm->getNextAlarm($curClient, 1);
	if (defined($curAlarm)) {
		$nAlarmTime = $curAlarm->findNextTime(time());
		$szAlarmClient = $curClient->name();
			
		if ( (!$nNextAlarmTime) || ($nAlarmTime < $nNextAlarmTime) ) {
			$nNextAlarmTime = $nAlarmTime;
			$szNextAlarmClient = $szAlarmClient;
		}
	}
}

return $nNextAlarmTime;

Shouldn't findNextTime() return the same epoch date/time for the alarm regardless of whether or not there is an intervening DST change?

I.E. if the system time is sixty seconds before a DST change, findNextTime(time()) returns one answer and  findNextTime(time()+61) returns a different answer.  To me, the former is the "wrong" answer.  Epoch time is epoch time and shouldn't change in this case, imho.


Comment 4 James Richardson 2009-02-23 13:58:58 UTC
Max, whats your though on the comment #3
Comment 5 Max Spicer 2009-02-24 01:20:56 UTC
I think Gordon has a point, but I don't think it's a problem that would affect the core alarm functionality.  We should probably fix this, but I wouldn't say it was a priority.  Off the top of my head, findNextTime probably needs to be using gmtime where it uses localtime, but it needs some careful thought.  Patches welcome!
Comment 6 Gordon Harris 2009-02-24 09:31:49 UTC
For what it's worth, I agree that this is of minor..or even trivial importance.  Max is, as far as I can tell, right in that there is currently no impact from this on the functionality of any SD hardware.  As long as the SqueezeCenter server keeps awake and running through the DST transition, alarms are serviced at the appropriate time.

With the SB Boom, if the server is down during a DST transition, the Boom's backup RTC alarm behaves like any dumb alarm clock...i.e. the backup alarm will sound an hour 'off'.

I raised this simply because I'm calling findNextTime() from the SrvrPowerCtrl plugin in order to schedule the server's RTC alarm to wake the server at the appropriate time.  Currently, my code has to compensate on DST transition days for the fact that findNextTime() returns the incorrect epoch date/time for the next alarm IF the DTS transition occurs between the call to findNextTime() and the actual alarm.

So..I raised this more in the spirit of an 'FYI' than something that presents a need with the currently released hardware.
Comment 7 Chris Owens 2009-03-02 09:29:44 UTC
Andy says, 'Patches welcome'
Comment 8 Gordon Harris 2009-03-02 09:43:38 UTC
Understood.  I'll start working on one.
Comment 9 Chris Owens 2009-03-04 14:12:07 UTC
I didn't mean to be brusque or demanding; we were just in a bug meeting and trying to get through a lot of bugs that needed review!

Thanks for anything you can contribute, or, if you find you can't finish the project, I hope your work so far can help another contributor, or an in-house developer at some point in the future.