HP3000-L Archives

April 1998, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Stan Sieler <[log in to unmask]>
Reply To:
Stan Sieler <[log in to unmask]>
Date:
Fri, 17 Apr 1998 00:24:19 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (194 lines)
Hi all,

If you saw Steve's posts about time(), that was an offline
conversation that leaked by accident.

FYI, here's what I said about it:



Ok...some answers...from the time people (HourGlass, remember :)

1) When you ask for GMT on MPE (by calling time() or HPGMTSECS),
   you get the time from the software clock, *NOT* the hardware clock.

   At bootup, the software reads the hardware clock (which is assumed to be
   in GMT (aka UTC)).

   MPE then computes the offset between the system local
   time and GMT (when it asks you what the local time is).
   That offset is saved.  (Let's call it the "GMT offset")

   From this point on, the system clock runs in local time.

   If you call gmt_secs, or HPGMTSECS, or time(), the software clock is
   fetched, the GMT offset is added to it, and poof...GMT time is returned.
   (Thus, if you had a crazy hardware clock setting, you get a crazy GMT time.)

   If you call CLOCK, CALENDAR, etc., the software clock is fetched, and
   the system local time is returned...GMT and TZ don't enter into it.

   The SETCLOCK command changes the system time and/or the GMT offset.


2) TZ

   TZ is fetched/decoded every time you call ctime() (or localtime())...
   (note the last two ctime() calls in the attached example)

   (note: true on HP-UX, AIX, and MPE/iX)

   If you use localtime (time()) on MPE:
      - GMT time is fetched:
         - the software clock is fetched;
         - the GMT offset is added to it;
      - TZ is fetched;
      - timezone is computed;
      - local time is computed (GMT - timezone);
        (possibly adjusting for daylight savings time)

   If you use localtime (time()) on HP-UX or AIX:
      - GMT time is fetched;
      - TZ is fetched;
      - timezone is computed;
      - local time is computed (GMT - timezone);
        (possibly adjusting for daylight savings time)

   (see the attached foo.c program, and the sample output)

   Note: on HP-UX and MPE/iX the initial value of TZ seems to be EST5EDT!
   (Probably because of the Apollo origins of HP-UX)

   Note that "timezone is computed" really means:

      - open tztab.lib.sys (on MPE) or /etc/tztab (HP-UX)

      - read the data, looking for a match with your TZ variable
        decode the data, return with a timezone offset

   ...that's not cheap.  MPE/iX has some kind of smarts whereby it
   attempts to mimimize the number of times it does this open/read stuff,
   but I haven't take the time to figure out what it is (probably caches
   TZ and timezone, and checks to see if they've changed when you call
   localtime (or, _tzset (a helper routine)).


-----------------------------------cut here----------------------------
/* foo.c ...compile with -Aa on MPE/iX */

#include <time.h>
#include <stdlib.h>

extern long timezone;

int main()
{

time_t
   gmt,
   gmt2,
   loc;

struct tm
   loc_tm;

int
   save_timezone;


save_timezone = timezone;

(void) printf ("\n");

(void) printf ("timezone = %d\n", timezone);     /* will be kernel's timezone (on HP-UX) */
(void) printf ("\n");

(void) time (&gmt);                              /* # seconds since 1970-01-01 */

if (timezone != save_timezone)
   {
   (void) printf ("**NOTE: time() changed timezone!\n");
   save_timezone = timezone;
   (void) printf ("timezone = %d\n", timezone);
   }

loc_tm = *localtime (&gmt);                      /* convert to local time */

if (timezone != save_timezone)
   {
   (void) printf ("**NOTE: localtime () changed timezone!\n\n");
   save_timezone = timezone;
   (void) printf ("timezone = %d\n", timezone);
   }

gmt2 = mktime (&loc_tm);                         /* convert back to GMT (as #seconds) */

printf ("time() --> %d (GMT), gmt2 = %d\n", gmt, gmt2);
(void) printf ("\n");

if (gmt != gmt2)
   (void) printf ("Note: localtime/mktime didn't convert GMT->local->GMT correctly\n");

(void) printf ("local time:\n");
(void) printf ("   ctime (&gmt)                  = %s\n", ctime (&gmt));

(void) printf ("   asctime (localtime (time ())) = %s\n",
           asctime (localtime (&gmt)));

(void) printf ("GMT:\n");
(void) printf ("   asctime (gmtime (&gmt))       = %s\n",
           asctime (gmtime (&gmt)));

(void) printf ("\n");

(void) printf ("calling tzset...\n");
(void) printf ("\n");

tzset();

(void) time (&gmt);
(void) printf ("local time:\n");
(void) printf ("   ctime (&gmt)                  = %s\n", ctime (&gmt));

      /* demonstrate that the TZ is fetched *every* time ctime() is called! */

putenv ("TZ=GMT");
(void) time (&gmt);
(void) printf ("GMT time:\n");
(void) printf ("   ctime (&gmt)                  = %s\n", ctime (&gmt));

return 0;
}

---------------------------------sample output-----------------------


timezone = 18000

**NOTE: localtime () changed timezone!

timezone = 28800
time() --> 892797550 (GMT), gmt2 = 892797550

local time:
   ctime (&gmt)                  = Fri Apr 17 00:19:10 1998

   asctime (localtime (time ())) = Fri Apr 17 00:19:10 1998

GMT:
   asctime (gmtime (&gmt))       = Fri Apr 17 07:19:10 1998


calling tzset...

local time:
   ctime (&gmt)                  = Fri Apr 17 00:19:10 1998
GMT time:
   ctime (&gmt)                  = Fri Apr 17 07:19:10 1998
          The above shows the affect of changing TZ within a program,
          and yet not calling tzset() afterwards (i.e., it still worked)

--
Stan Sieler                                          [log in to unmask]
                                     http://www.allegro.com/sieler.html

ATOM RSS1 RSS2