src/os/win32/ngx_time.c - nginx source code

Functions defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #include <ngx_config.h>
  6. #include <ngx_core.h>


  7. void
  8. ngx_gettimeofday(struct timeval *tp)
  9. {
  10.     uint64_t  intervals;
  11.     FILETIME  ft;

  12.     GetSystemTimeAsFileTime(&ft);

  13.     /*
  14.      * A file time is a 64-bit value that represents the number
  15.      * of 100-nanosecond intervals that have elapsed since
  16.      * January 1, 1601 12:00 A.M. UTC.
  17.      *
  18.      * Between January 1, 1970 (Epoch) and January 1, 1601 there were
  19.      * 134774 days,
  20.      * 11644473600 seconds or
  21.      * 11644473600,000,000,0 100-nanosecond intervals.
  22.      *
  23.      * See also MSKB Q167296.
  24.      */

  25.     intervals = ((uint64_t) ft.dwHighDateTime << 32) | ft.dwLowDateTime;
  26.     intervals -= 116444736000000000;

  27.     tp->tv_sec = (long) (intervals / 10000000);
  28.     tp->tv_usec = (long) ((intervals % 10000000) / 10);
  29. }


  30. void
  31. ngx_libc_localtime(time_t s, struct tm *tm)
  32. {
  33.     struct tm  *t;

  34.     t = localtime(&s);
  35.     *tm = *t;
  36. }


  37. void
  38. ngx_libc_gmtime(time_t s, struct tm *tm)
  39. {
  40.     struct tm  *t;

  41.     t = gmtime(&s);
  42.     *tm = *t;
  43. }


  44. ngx_int_t
  45. ngx_gettimezone(void)
  46. {
  47.     u_long                 n;
  48.     TIME_ZONE_INFORMATION  tz;

  49.     n = GetTimeZoneInformation(&tz);

  50.     switch (n) {

  51.     case TIME_ZONE_ID_UNKNOWN:
  52.         return -tz.Bias;

  53.     case TIME_ZONE_ID_STANDARD:
  54.         return -(tz.Bias + tz.StandardBias);

  55.     case TIME_ZONE_ID_DAYLIGHT:
  56.         return -(tz.Bias + tz.DaylightBias);

  57.     default: /* TIME_ZONE_ID_INVALID */
  58.         return 0;
  59.     }
  60. }