home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / libc / gen / timezone.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  941 b   |  45 lines

  1. /*
  2.  * The arguments are the number of minutes of time
  3.  * you are westward from Greenwich and whether DST is in effect.
  4.  * It returns a string
  5.  * giving the name of the local timezone.
  6.  *
  7.  * Sorry, I don't know all the names.
  8.  */
  9.  
  10. static struct zone {
  11.     int    offset;
  12.     char    *stdzone;
  13.     char    *dlzone;
  14. } zonetab[] = {
  15.     4*60, "AST", "ADT",        /* Atlantic */
  16.     5*60, "EST", "EDT",        /* Eastern */
  17.     6*60, "CST", "CDT",        /* Central */
  18.     7*60, "MST", "MDT",        /* Mountain */
  19.     8*60, "PST", "PDT",        /* Pacific */
  20.     0, "GMT", 0,            /* Greenwich */
  21.     -1
  22. };
  23.  
  24. char *timezone(zone, dst)
  25. {
  26.     register struct zone *zp;
  27.     static char czone[10];
  28.     char *sign;
  29.  
  30.     for (zp=zonetab; zp->offset!=-1; zp++)
  31.         if (zp->offset==zone) {
  32.             if (dst && zp->dlzone)
  33.                 return(zp->dlzone);
  34.             if (!dst && zp->stdzone)
  35.                 return(zp->stdzone);
  36.         }
  37.     if (zone<0) {
  38.         zone = -zone;
  39.         sign = "+";
  40.     } else
  41.         sign = "-";
  42.     sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60);
  43.     return(czone);
  44. }
  45.