home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_02 / 1102021a < prev    next >
Text File  |  1992-12-09  |  768b  |  34 lines

  1. /* localtime function */
  2. #include <stdlib.h>
  3. #include "xtime.h"
  4.  
  5. time_t _Tzoff(void)
  6.     {    /* determine local time offset */
  7.     static const char *oldzone = NULL;
  8.     static long tzoff = 0;
  9.     static const long maxtz = 60*13;
  10.  
  11.     if (oldzone != _Times._Tzone)
  12.         {    /* determine time zone offset
  13.             (East is +) */
  14.         const char *p, *pe;
  15.         int n;
  16.  
  17.         if (_Times._Tzone[0] == '\0')
  18.             _Times._Tzone = _Getzone();
  19.         p = _Gettime(_Times._Tzone, 2, &n);
  20.         tzoff = strtol(p, (char **)&pe, 10);
  21.         if (pe - p != n
  22.             || tzoff <= -maxtz || maxtz <= tzoff)
  23.             tzoff = 0;
  24.         oldzone = _Times._Tzone;
  25.         }
  26.     return (-tzoff * 60);
  27.     }
  28.  
  29. struct tm *(localtime)(const time_t *tod)
  30.     {    /* convert to local time structure */
  31.     return (_Ttotm(NULL, *tod + _Tzoff(), -1));
  32.     }
  33.  
  34.