Changeset 664


Ignore:
Timestamp:
Sep 8, 2003, 9:56:28 PM (22 years ago)
Author:
zap
Message:

fixed timezone handling.

Location:
trunk/src/emx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/time.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r663 r664  
    1818struct tm;
    1919
     20/* Maximum length for time zone standard - "GMT", "CEST" etc. */
     21#define __MAX_TZ_STANDARD_LEN 15
     22
    2023struct _tzinfo
    2124{
    22   char tzname[4];
    23   char dstzname[4];
     25  char tzname[__MAX_TZ_STANDARD_LEN + 1];
     26  char dstzname[__MAX_TZ_STANDARD_LEN + 1];
    2427  int tz, dst, shift;
    2528  int sm, sw, sd, st;
  • trunk/src/emx/src/lib/sys/__ftime.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r663 r664  
    77#include <emx/time.h>
    88#include <emx/syscalls.h>
     9#include <386/builtin.h>
    910#include "syscalls.h"
    1011
     12/* Return time in local format */
    1113void __ftime (struct timeb *ptr)
    1214{
     
    2123  tm.tm_mon = now.month - 1;
    2224  tm.tm_year = now.year - 1900;
    23   tm.tm_isdst = -1;             /* unknown */
     25
    2426  ptr->time = (time_t)_mktime (&tm);
     27  /* Apply timezone correction to get UTC time since we don't know what
     28     timezone DosGetDateTime uses and whether it honors the TZ variable.
     29     Then apply application's own timezone to get local time back. */
     30  if (now.timezone != -1)
     31    ptr->time = ptr->time - (long)now.timezone * 60 + _tzi.tz;
    2532  ptr->millitm = now.hundredths * 10;
    26   ptr->timezone = now.timezone;
    27   ptr->dstflag = 0;
    2833}
  • trunk/src/emx/src/lib/time/ftime.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r663 r664  
    1515  t_loc = ptr->time;
    1616  ptr->dstflag = _loc2gmt (&ptr->time, -1);
    17   ptr->timezone = (int)(ptr->time - t_loc) / 60;
     17  ptr->timezone = _tzi.tz / 60;
    1818}
  • trunk/src/emx/src/lib/time/gettimeo.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r663 r664  
    2525  if (tzp != NULL)
    2626    {
    27       tzp->tz_minuteswest = (int)(tb.time - t_loc) / 60;
     27      tzp->tz_minuteswest = _tzi.tz / 60;
    2828      tzp->tz_dsttime = dst;
    2929    }
  • trunk/src/emx/src/lib/time/tzset.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r663 r664  
    1010#include <emx/syscalls.h>
    1111
    12 int _daylight = 0;
    13 long _timezone = 0;
    14 char *_tzname[2] = {"GMT", ""};
     12int _STD(daylight) = 0;
     13long _STD(timezone) = 0;
     14char *_STD(tzname)[2] = {"GMT", ""};
    1515
    1616struct _tzinfo _tzi = {"GMT", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
     
    8888  p = *pp;
    8989
    90   /* Check the supposed timezone name for validity.  See ISO 9945-1,
    91      8.1.1 for details. */
    92 
    93   if (*p == ':' || (*p >= '0' && *p <= '9'))
    94     return 0;
    95   for (i = 0; i < 3; ++i)
    96     if (p[i] == 0 || p[i] == ',' || p[i] == '-' || p[i] == '+')
    97       return 0;
     90  /* Check the supposed timezone name for validity.
     91     See ISO 9945-1, 8.1.1 for details. */
     92  if (!(i = strcspn (p, ":,+-")))
     93    return 0;
    9894
    9995  /* The timezone name is valid. */
    100 
    101   memcpy (dst, p, 3);
    102   dst[3] = 0;
    103   *pp = p + 3;
    104   return 1;
    105 }
    106 
    107 
     96  *pp = p + i;
     97  if (i > __MAX_TZ_STANDARD_LEN)
     98    i = __MAX_TZ_STANDARD_LEN;
     99  memcpy (dst, p, i);
     100  dst [i] = 0;
     101  return 1;
     102}
     103
     104static int parse_delta (char **src, int *offset, int opt_sign)
     105{
     106  int ofs = 0, sign = 1, temp;
     107
     108  if (!dnum (&ofs, src, -23, 23, opt_sign, -1))
     109    return 0;
     110  if (ofs < 0)
     111    sign = -1, ofs = -ofs;
     112
     113  ofs *= 60;
     114  if (**src == ':')            /* Minutes specified? */
     115    {
     116      (*src)++;
     117      if (!dnum (&temp, src, 0, 59, 0, -1))
     118        return 0;
     119      ofs += temp;
     120    }
     121
     122  ofs *= 60;
     123  if (**src == ':')            /* Seconds specified? */
     124    {
     125      (*src)++;
     126      if (!dnum (&temp, src, 0, 59, 0, -1))
     127        return 0;
     128      ofs += temp;
     129    }
     130
     131  *offset = sign > 0 ? ofs : -ofs;
     132
     133  return 1;
     134}
     135
     136static int parse_switchtime (char **src, int *m, int *w, int *d, int *t)
     137{
     138  if (!dnum (m, src, 1, 12, 0, ',')
     139   || !dnum (w, src, -4, 4, 1, ',')
     140   || !dnum (d, src, *w ? 0 : 1, *w ? 6 : 31, 0, ',')
     141   || !dnum (t, src, 0, 86399, 0, ','))
     142    return 0;
     143
     144  return 1;
     145}
     146
     147/* The format of TZ environment variable:
     148 *
     149 * TZ1[OFF,[TZ2[,SM,SW,SD,ST,EM,EW,ED,ET,SHIFT]]]
     150 *
     151 * TZ1 is the at least three-letter name of the standard timezone.
     152 *
     153 * OFF is the offset to Coordinated Universal Time; positive values are to the
     154 * west of the Prime Meridian, negative values are to the east of the Prime
     155 * Meridian. The offset has the format [H[:M[:S]]].
     156 *
     157 * TZ2 is the three-letter name of the summer timezone (daylight saving time).
     158 * If TZ2 is not specified, daylight saving time does not apply.
     159 *
     160 * SM specifies the month (1 through 12) of the change. SW specifies the week
     161 * of the change; if this value is zero, SD specifies the day of month
     162 * (1 through 31). If SW is positive (1 through 4), the change occurs on
     163 * weekday SD (0=Sunday through 6=Saturday) of the SWth week of the specified
     164 * month. The first week of a month starts on the first Sunday of the month.
     165 * If SW is negative (-1 through -4), the change occurs on weekday SD
     166 * (0=Sunday through 6=Saturday) of the -SWth week of the specified month,
     167 * counted from the end of the month (that is, -1 specifies the last week of
     168 * the month). The last week of a month starts on the last Sunday of the
     169 * month. ST specifies the time of the change, in seconds. Note that ST is
     170 * specified in local standard time and ET is specified in local daylight
     171 * saving time.
     172 *
     173 * Example:
     174 *   CET-1CED,3,-1,0,7200,10,-1,0,10800,3600
     175 *   KWT-4KWST,3,-1,0,7200,10,-1,0,10800,3600
     176 */
    108177void _STD(tzset) (void)
    109178{
     
    111180  struct timeb tb;
    112181  char *p;
    113   int sign, offset, temp;
     182  int offset;
    114183  time_t t_loc;
    115184
    116185  p = getenv ("TZ");
    117   if (p == NULL)
    118     p = "GMT0";                 /* Our best approximation :-) */
    119   if (*p == 0)
    120     p = "GMT0";
     186  if (p == NULL || *p == 0)
     187    p = "GMT";                  /* Our best approximation :-) */
    121188
    122189  if (!copy_tzname (ntz.tzname, &p))
     
    124191
    125192  if (*p == 0)
    126     offset = sign = 0;          /* TZ=XYZ is valid (in contrast to POSIX.1) */
    127   else
    128     {
    129       if (!dnum (&offset, &p, -24, 24, 1, -1))
    130         return;
    131       if (offset < 0)
    132         sign = -1, offset = -offset;
    133       else
    134         sign = 1;
    135 
    136       offset *= 60;
    137       if (*p == ':')            /* Minutes specified? */
    138         {
    139           ++p;
    140           if (!dnum (&temp, &p, 0, 59, 0, -1))
    141             return;
    142           offset += temp;
    143         }
    144 
    145       offset *= 60;
    146       if (*p == ':')            /* Seconds specified? */
    147         {
    148           ++p;
    149           if (!dnum (&temp, &p, 0, 59, 0, -1))
    150             return;
    151           offset += temp;
    152         }
    153     }
    154 
    155   ntz.tz = sign > 0 ? offset : -offset;
     193    offset = 0;                 /* TZ=XYZ is valid (in contrast to POSIX.1) */
     194  else if (!parse_delta (&p, &offset, 1))
     195    return;
     196
     197  ntz.tz = offset;
    156198
    157199  ntz.dst = 0;
     
    162204      ntz.dst = 1;
    163205      if (!copy_tzname (ntz.dstzname, &p))
    164         return ;
     206        return;
    165207      if (*p == ',')
    166208        {
    167           ++p;
    168           if (!dnum (&ntz.sm, &p, 1, 12, 0, ',')
    169               || !dnum (&ntz.sw, &p, -4, 4, 1, ',')
    170               || !dnum (&ntz.sd, &p, ntz.sw ? 0 : 1, ntz.sw ? 6 : 31, 0, ',')
    171               || !dnum (&ntz.st, &p, 0, 86399, 0, ',')
    172               || !dnum (&ntz.em, &p, 1, 12, 0, ',')
    173               || !dnum (&ntz.ew, &p, -4, 4, 1, ',')
    174               || !dnum (&ntz.ed, &p, ntz.ew ? 0 : 1, ntz.ew ? 6 : 31, 0, ',')
    175               || !dnum (&ntz.et, &p, 0, 86399, 0, ',')
    176               || !dnum (&ntz.shift, &p, 0, 86400, 0, 0))
     209          p++;
     210          /* Parse DST start date/time */
     211          if (!parse_switchtime (&p, &ntz.sm, &ntz.sw, &ntz.sd, &ntz.st))
     212            return;
     213          if (!parse_switchtime (&p, &ntz.em, &ntz.ew, &ntz.ed, &ntz.et))
     214            return;
     215          if (!dnum (&ntz.shift, &p, 0, 86400, 0, 0))
    177216            return;
    178217        }
     
    180219        {
    181220          /* VAC++ default values */
    182 
    183221          ntz.sm = 4;  ntz.sw =  1; ntz.sd = 0; ntz.st = 3600;
    184222          ntz.em = 10; ntz.ew = -1; ntz.ed = 0; ntz.et = 7200;
     
    194232  /* TODO: Make this thread-safe! */
    195233  _tzi = ntz;
    196   _tzname[0] = _tzi.tzname;
    197   _tzname[1] = _tzi.dstzname;
     234  _STD(tzname)[0] = _tzi.tzname;
     235  _STD(tzname)[1] = _tzi.dstzname;
    198236  _compute_dst_table ();
    199237
    200238  __ftime (&tb);
    201239  t_loc = tb.time;
    202   _daylight = _loc2gmt (&tb.time, -1);
    203   _timezone = (int)(tb.time - t_loc);
     240  _STD(daylight) = _loc2gmt (&tb.time, -1);
     241  _STD(timezone) = _tzi.tz;
    204242
    205243  _tzset_flag = 1;
Note: See TracChangeset for help on using the changeset viewer.