1834814 Members
3024 Online
110070 Solutions
New Discussion

Re: When does DST start?

 
SOLVED
Go to solution
Greg White
Frequent Advisor

When does DST start?

Hello experts,

I have been asked to come up with a way to determine if Daylight Saving Time begins during the coming weekend. The idea is that on Monday morning before the change happens that weekend, I would like to be able to send out notices. I have looked at /usr/lib/tztab but that seems very complicated to me. Any ideas out there?

TIA. Greg
I know how to do it in pascal.
8 REPLIES 8
Cheryl Griffin
Honored Contributor

Re: When does DST start?

This year it starts April 6 at 2 am DST
Cheryl
"Downtime is a Crime."
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: When does DST start?

Hi Greg:

I would have a cron job that runs each Monday morning that calls the following one minute perl snippet. It looks at the DST setting for today and 1 week later and compares them.
---------------------------
#!/usr/bin/perl -w
use strict;

use constant SECONDS_PER_DAY => (24 * 60 * 60);
use constant DAYS_PER_WEEK => 7;

my $epoch = time();
my $isdst = (localtime($epoch))[8];
$epoch += (DAYS_PER_WEEK * SECONDS_PER_DAY);
my $isdst2 = (localtime($epoch))[8];
printf("%d\n",$isdst2 - $isdst);

---------------------------

This will print "1" going from Standard Time to DST; "-1" going from DST to Standard Time; and "0" if no change.

That should get you started, Clay
If it ain't broke, I can fix that.
Cheryl Griffin
Honored Contributor

Re: When does DST start?

There are sites like http://www.energy.ca.gov/daylightsaving.html which has the history of DST but one that might help in your planning is this one http://webexhibits.org/daylightsaving/b.html You can change the Year at the bottom of the page for planning and see years in advance when to expect the change.

DST starts the first Sunday of every April.
Cheryl
"Downtime is a Crime."
James R. Ferguson
Acclaimed Contributor

Re: When does DST start?

Hi Greg:

This isn't as mysterious as it first appears. The man pages for 'tztab(4)' give a good explanation.

For "Eastern Standard Time, Eastern Daylight Time" (where I reside), the next time change during the years 1987-2038 occurs on the first Sunday (day=0) of the 4th month (April) during the first seven days (1-7).

Looking at a calendar, this maps to Sunday, April 6, 2003.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: When does DST start?

One more point, Greg:

This does assume that TZ has been set and also if you have users in multiple timezones you might need a cronjob for each with appropriate TZ settings for each.
If it ain't broke, I can fix that.
Greg White
Frequent Advisor

Re: When does DST start?

Thanks everybody! That was fast! I cut and pasted A. Clay's Perl script and it does just what I need.

Greg
I know how to do it in pascal.
Greg White
Frequent Advisor

Re: When does DST start?

Just thought I would give you an update. I used the Perl script and it works great although I can't test it. I did change it to simply exit with 1,0, or -1 instead of printing the result.
If the exit status is 0, the script does nothing but if it is -1 or 1 it sends mail to the users.

Thanks everybody for your help.
Greg
I know how to do it in pascal.
A. Clay Stephenson
Acclaimed Contributor

Re: When does DST start?

Hi Greg:

Actually you should be able to 'trick' it into returning a DST change. Simply increase the $epoch value more than 1 week where the $epoch += (SECONDS_PER_DAY * DAYS_PER_WEEK) is. make it something like $epoch += (SECONDS_PER_DAY * DAYS_PER_WEEK * 8).

I would let the Perl script print the output and test that
because the shell is going to see an unsigned exit status in the range 0-255.
If it ain't broke, I can fix that.