apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@apache.org
Subject cvs commit: apr/time/win32 time.c
Date Fri, 02 Feb 2001 14:43:54 GMT
stoddard    01/02/02 06:43:53

  Modified:    .        CHANGES
               time/win32 time.c
  Log:
  Win32:    (IsLeapYear): New macro for quickly figgerin' out if a given year is a
  leap year. (SystemTimeToAprExpTime): Perform the calculation of
  tm_yday.  Also, negate the sign of the tm_gmtoff field to be
  consistent with Unix platforms and APR header file comments.
  
  ToDo: Perhaps the IsLeapYear macro is useful for other OSes.
  
  Submitted by:  Mike Pilato
  Reviewed by:  Bill Stoddard
  
  Revision  Changes    Path
  1.54      +6 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- CHANGES	2001/01/29 06:21:37	1.53
  +++ CHANGES	2001/02/02 14:43:51	1.54
  @@ -1,4 +1,10 @@
   Changes with APR b1  
  +  *) Some fixes in the Win32 time support.
  +     (IsLeapYear): New macro for quickly figgerin' out if a given year is a 
  +     leap year. (SystemTimeToAprExpTime): Perform the calculation of
  +     tm_yday.  Also, negate the sign of the tm_gmtoff field to be
  +     consistent with Unix platforms and APR header file comments.
  +     [Mike Pilato]
   
     *) Implement WinNT Unix'ish permissions. [William Rowe]
   
  
  
  
  1.17      +17 -3     apr/time/win32/time.c
  
  Index: time.c
  ===================================================================
  RCS file: /home/cvs/apr/time/win32/time.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- time.c	2001/01/18 20:07:38	1.16
  +++ time.c	2001/02/02 14:43:53	1.17
  @@ -77,6 +77,7 @@
       *result -= APR_DELTA_EPOCH_IN_USEC;  /* Convert from Windows epoch to Unix epoch */
       return;
   }
  +
   void AprTimeToFileTime(LPFILETIME pft, apr_time_t t)
   {
       LONGLONG ll;
  @@ -87,10 +88,17 @@
       return;
   }
   
  +/* Leap year is any year divisible by four, but not by 100 unless also
  + * divisible by 400
  + */
  +#define IsLeapYear(y) ((!(y % 4)) ? (((!(y % 400)) && (y % 100)) ? 1 : 0) : 0)
  +
   void SystemTimeToAprExpTime(apr_exploded_time_t *xt, SYSTEMTIME *tm)
   {
       TIME_ZONE_INFORMATION tz;
       DWORD rc;
  +    static const int dayoffset[12] =
  +    {0, 31, 59, 90, 120, 151, 182, 212, 243, 273, 304, 334};
   
       xt->tm_usec = tm->wMilliseconds * 1000;
       xt->tm_sec  = tm->wSecond;
  @@ -100,7 +108,13 @@
       xt->tm_mon  = tm->wMonth - 1;
       xt->tm_year = tm->wYear - 1900;
       xt->tm_wday = tm->wDayOfWeek;
  -    xt->tm_yday = 0; /* ToDo: need to compute this */
  +    xt->tm_yday = dayoffset[xt->tm_mon] + (tm->wDay - 1);
  +
  +    /* If this is a leap year, and we're past the 28th of Feb. (the
  +     * 58th day after Jan. 1), we'll increment our tm_yday by one.
  +     */
  +    if (IsLeapYear(tm->wYear) && (xt->tm_yday > 58))
  +        xt->tm_yday++;
   
       rc = GetTimeZoneInformation(&tz);
       switch (rc) {
  @@ -110,11 +124,11 @@
           /* Bias = UTC - local time in minutes 
            * tm_gmtoff is seconds east of UTC
            */
  -        xt->tm_gmtoff = tz.Bias * 60;
  +        xt->tm_gmtoff = tz.Bias * -60;
           break;
       case TIME_ZONE_ID_DAYLIGHT:
           xt->tm_isdst = 1;
  -        xt->tm_gmtoff = tz.Bias * 60;
  +        xt->tm_gmtoff = tz.Bias * -60;
           break;
       default:
           xt->tm_isdst = 0;
  
  
  

Mime
View raw message