Need help with 'time' C Run-Time Library functions under HP-UX

Need help with 'time' C Run-Time Library functions under HP-UX

Post by Andrew Giert » Wed, 12 Feb 1997 04:00:00



 timd> I'm trying to get some help with 'time' C Run-Time Library functions
 timd> under HP-UX.  Here's the nature of the problem:

 timd> Say you have a system where the kernel parameters for timezone
 timd> are set to Mountain Standard Time, and you set the system date
 timd> using the 'date' command for January 1, 1970 (the start of UNIX
 timd> time).

 timd> The time () function will always return a value offset by the
 timd> timezone set in the kernel.

Nope. time() always returns GMT - the kernel timezone is not used.

 timd> Now say that you want to construct a time from scratch in a client
 timd> process in a different timezone.

 timd>       export TZ=AST4ADT       (Atlantic Daylight Savings Time)

 timd> If you try to construct a time for January 1, 1970 using the
 timd> 'mktime' function you will not achieve the correct results.

 timd>       struct tm timeStruct;
 timd>       time_t    timeValue;

 timd>       memset (&timeStruct, 0, sizeof (struct tm));
 timd>       timeStruct.tm_year = 70;
 timd>       timeStruct.tm_mon  = 0;       (month - 1)
 timd>       timeStruct.tm_mday = 1;

 timd>       timeValue = mktime (&timeStruct);

 timd>       timeValue = 14400;

 timd> Notice that the time value returned only takes into account the
 timd> local time zone set in the TZ environment variable.

That's correct.

 timd> I'm trying to find a way in HP-UX to determine what the system clock
 timd> time zone offset (e.g. 25,200) is.

You don't need it.

 timd> I've noticed that there is a 'gettimeofday' non-ANSI call under
 timd> HP-UX that returns me the minutes west of Greenwich.  This gets me
 timd> close, but still does not tell me whether Daylight Savings Time
 timd> is in effect for the kernel time zone, only whether Daylight Savings
 timd> Time gets used for the time zone.

Forget about the kernel timezone - it's never visible at user level
(gettimeofday can read it, but there's never any reason to). It is a
historical fossil only.

As far as time(), and *every* system call that takes or returns timestamps
is concerned, there is no timezone, only seconds since 1-1-70 0:00 GMT.
Timezones are only used to convert between seconds-since-Epoch and forms
more meaningful to the user.

HTH

--
Andrew.

 
 
 

Need help with 'time' C Run-Time Library functions under HP-UX

Post by Stephen Bayn » Wed, 12 Feb 1997 04:00:00


: I'm trying to get some help with 'time' C Run-Time Library functions
: under HP-UX.  Here's the nature of the problem:

: Say you have a system where the kernel parameters for timezone are
: set to Mountain Standard Time, and you set the system date
: using the 'date' command for January 1, 1970 (the start of UNIX time).
Do you mean set time to 00:00 01/01/1970 MST or
Do you mean set time to 00:00 01/01/1970 GMT which is the start of UNIX time.

: The time () function will always return a value offset by the
: timezone set in the kernel.
It will always return a GMT based time.

: If you try to construct a time for January 1, 1970 using the
: 'mktime' function you will not achieve the correct results.

: Notice that the time value returned only takes into account the local time
: zone set in the TZ environment variable.

Which is correct.

--

Philips Semiconductors Ltd                  
Southampton SO15 0DJ                        +44 (01703) 316431
United Kingdom                              My views are my own.
Do you use ISO8859-1? Yes if you see ? as copyright, as division and ? as 1/2.