1826989 Members
3307 Online
109705 Solutions
New Discussion

How does TZ get set?

 
SOLVED
Go to solution
Adam Garsha
Valued Contributor

How does TZ get set?

On one of our older HP-UX boxes:

TZ=CST6

on our newer boxes:

TZ=CST6CDT
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: How does TZ get set?

Hi Adam:

Assuming a Posix shell, when /etc/profile is sourced during login, /etc/TIMEZONE is sourced (if avaailable).

In turn, /etc/TIMEZONE is intended to contain the default TZ variable.

Regards!

...JRF...
Adam Garsha
Valued Contributor

Re: How does TZ get set?

oh, looks like /etc/TIMEZONE

Follow-up question:

looking at /usr/lib/tztab I don't find a category for explicitly CST6. Namely, I find this:

# Central Standard Time, Central Daylight Time
CST6CDT
0 3 24-30 4 1970-1973 0 CDT5
0 3 6 1 1974 0-6 CDT5
0 3 22-28 2 1975 0 CDT5
0 3 24-30 4 1976-1986 0 CDT5
0 3 1-7 4 1987-2038 0 CDT5
0 1 25-31 10 1970-1973 0 CST6
0 1 24-30 11 1974 0 CST6
0 1 25-31 10 1975-2038 0 CST6

If TZ=CST6, how does or when does a daylight savings time change occur? Never? Thanks.

Why I ask. The time flopped back an hour on one of our HP-UX 10 boxes. I am trying to find the cause.
DCE
Honored Contributor

Re: How does TZ get set?

You can set it with

set_parms timezone

or modify /etc/defaults/tz (this may require a reboot to take effect - I do not know)
Steven E. Protter
Exalted Contributor

Re: How does TZ get set?

Check and see if the box is using ntp (ntp.conf) to connect to an internal time server.

That time server may be off or non-standard, thoght the change would not be sudden in this case, it would be very gradual.

I would run through /etc/profile and .profile and stuff and look for source that might be altering the TZ variable. Its probably a pecularity of this box.

If you change the TIMEZONE parameter it should solve the problem, though a manual time zone adjust ment may be needed.

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
Bill Hassell
Honored Contributor
Solution

Re: How does TZ get set?

Let's see if I can clear this up a bit. First, HP-UX knows NOTHING about any timezones. HP-UX maintains time in one format: UTC (or the legacy term GMT). No daylight saving, no timezones, nothing but (very useful) UTC time. And no, HP-UX NEVER changes time for daylight saving.

Q: So where do all these timezones come into play?

ANS: Through the standard Unix libraries and commands. Whether you run the date command or use libary calls like ctime(), etc, the environment value of TZ is checked and then based on the rules in /usr/lib/tztab (or if not found in tztab, the rules found in the environ man page) will be applied to the UTC system time and time (possibly date) translated accordingly.

Since CST6 is not found in tztab, the man page for environ says that when TZ=CST6, 6 hours must be added to match UTC time. And since there is no daylight saving part, then no daylight saving rule will be observed. So just change /etc/TIMEZONE to read:

TZ=CST6CDT
export TZ

Now each user that logs in will see Central time including the apparent jump for daylight saving. So TZ is merely a translator and never changes the system time. only it's representation.

What about /etc/defaults/tz? This is a relatively recent patch (PHCO_31927) which also needs an updated libc patch. Read the description for PHCO_31927 for the details. Note that set_parms timezone just edits /etc/TIMEZONE, so you can do this at anytime. When this file changes, nothing is changed for existing logins--users must login again to get the new value.

As far as NTP, it will never change the time an hour forward or backward. NTP is based on UTC and does not do anything about daylight saving. So when you see the time 'jump', unless a root user has changed the time (a VERY bad idea on any production server), the TZ value has likely changed. To see this, type these commands to see how TZ affects the date command:

TZ=CST6 date
TZ=CST6CDT date
TZ=EST5EDT date
TZ=GMT0 date
TZ=NST3:30NDT date
TZ=CST-9:30CDT date
TZ=BILLH1:23 date

Notice that the date/time is displayed differently depending on the setting for TZ. UTC is always 6 hours ahead of CST6 year 'round, but CST6CDT will observe the rules in tztab. EST5EDT is the standard Eastern timezone with EDT observance. GMT0 is the same as UTC time.

Now for some fun: NST3:30NDT is for Newfoundland where there is a 30 minute (not 60 minute) change for daylight saving. And CST-9:30CDT is for South Australia and the offset is negative (-9:30). And the last is to demonstrate the versatility of the HP-UX TZ variable--I've created my own timezone!! According to the man page for environ, 3 (or more) bytes define the name, followed by the offset that must be added to local time to match UTC. So my special timezone says that UTC is 1 hour and 23 minutes behind UTC.

As you may already know, timezones have virtually nothing to do with geography and astronomy--they are purely political and subject to the whims of government. The good news is that HP-UX can accomodate those whims.

The /etc/default/tz file is used to help define the default TZ value when it is not defined (for instance, in /etc/inittab). The rules are:

1) if the environment variable TZ is present, it takes precedence.
2) if TZ is not present, then the value contained in /etc/default/tz is used for the default TZ.
3) if /etc/default/tz is not present, then the default TZ value is equivalent to EST5EDT (Eastern Standard Time) of US.


Bill Hassell, sysadmin