Operating System - HP-UX
1834004 Members
2003 Online
110063 Solutions
New Discussion

Re: Days until time change?

 
SOLVED
Go to solution
Robert Comber
Advisor

Days until time change?

Hi experts:

I have been asked to send notices indicating the numbers of days remaining until the change to standard time. Is there a command that will display when the time changes? Date doesn't seem to have an option for this.

Thanks,
Bob
13 REPLIES 13
Bill Hassell
Honored Contributor

Re: Days until time change?

The answer is: HP-UX never changes the system time. You are seeing a translated version of the date/time by virtue of the TZ variable. The man pages for env and tztab will show you how timezones are defined--you can even make up your own. And most important: 10 users can log on to your system, each with a different TZ setting and each may see a different date for the change. So the answer is in tztab, as long as $TZ contains an entry in /usr/lib/tztab.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: Days until time change?

Hi Bob:

The rules for timezone changes can be found in '/usr/lib/tztab'.

To help you understand it, see the manpages for 'tztab' too.

Regards!

...JRF...
Kent Ostby
Honored Contributor

Re: Days until time change?

Bob -- There are rules in the tztab file for each timezone.

I generally just use google to figure out what day the time change is :-)

"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Steven E. Protter
Exalted Contributor

Re: Days until time change?

I would suggest writing a little script, calling to http://www.hpux.ws/caljd.sh that changes the /etc/motd file

We've already changed our time in Israel, which is messing up all my communications plans for the US. I literally don't know what time it is and my PC has to be set to the Iraq time zone to keep proper time here.

Strange.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Arunvijai_4
Honored Contributor

Re: Days until time change?

You can use # env |grep "TZ"
TZ=EST5EDT

and try checking the differences.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Jannik
Honored Contributor

Re: Days until time change?

take a look at the calculation:
http://webexhibits.org/daylightsaving/i.html
jaton
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Days until time change?

While it is quite true that the system time never changes - all known UNIX boxes simply count seconds since the Earth was created - 1-Jan-1970 00:00:00; the manner in which these epoch seconds is displayed does change. The attached Perl script will do the job for you. (I wrote it because I got tired of answering the same dumb question over and over.)

DAYS=$(dst.pl -d)
echo "${DAYS} until the next time change.")

Add the -e option to display the truncated integer value. Invoke as dst.pl -u for full usage. If you install Perl on your Windoes box, it will even work there.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Days until time change?

Ooops, I'm an idiot.

DAYS=$(dst.pl -d)
echo "${DAYS} until the next time change.")

should be:

DAYS=$(dst.pl -d)
echo "${DAYS} until the next time change."

I don't know who added that superfluous (and unnecessary) ')'.


If it ain't broke, I can fix that.
Jeff Carlin
Frequent Advisor

Re: Days until time change?

Clay, are you going to update your script for the extension to daylight savings time in 2007?
Where wisdom is called for, force is of little use. --Of course, a hammer does wonders for relieving stress.
A. Clay Stephenson
Acclaimed Contributor

Re: Days until time change?

No, I shouldn't have to. This Perl script uses the same underlying functions (localtime(), strftime(), etc.) that all UNIX utilities such as the date command use. Whenever, the libc patches are released or the revised tztab entries are available, the Perl script will just work. It really doesn't know anything itself about timechanges but trusts that the underlying functions do. HP-UX is unique in that it does have a user-configurable tztab file. Almost all other flavors of UNIX (or Windows) will require library patches.
If it ain't broke, I can fix that.
Jeff Carlin
Frequent Advisor

Re: Days until time change?

I always learn something from you Clay!
Where wisdom is called for, force is of little use. --Of course, a hammer does wonders for relieving stress.
Bill Hassell
Honored Contributor

Re: Days until time change?

And just to add to Clay's comments, timezones are political definitions, so anyone can make up their own timezone and daylight saving rules--and change them every few years (which happens in many parts of the world). Because tztab can be instantly customized, you can create your own special timezone (or whatever the governements decide). Here's mine:

export TZ=BILLH5:21

Now when I type the date command, it offsets GMT -5 hours and 21 minutes with no daylight saving rule. I know, it's a dumb timezone but it illustrates how easy it is to change the way time is displayed. NOTE: setting the date/time always uses the current value of $TZ so make sure it is correct if you decide to experiment. And in general, setting the date and time on a production system is not a good idea. That's why NTP exists.


Bill Hassell, sysadmin
A. Clay Stephenson
Acclaimed Contributor

Re: Days until time change?

As a further note, it would be rather useless to have a utility that figured out itself how the time changes. What you really want is a tool that tests the system itself --- which is just what the dst.pl script does. Moreover, you can test it for multiple TZ settings just like a real UNIX box might have many TZ's in play simultaneously:

dst.pl -n # use default TZ
TZ=EST5EDT dst.pl -n # use Eastern (U.S.)
TZ=PST8PDT dst.pl -n # use Pacific (U.S.)

In this mode, dst.pl will display the time 1 second before and the exact second of the time change (if the time actually changes). If using a TZ that does not change (e.g. GMT0) then the output is null (and a non-zero status is returned).
If it ain't broke, I can fix that.