ReactOS  0.4.14-dev-1332-g6db3d88
mktime.c File Reference
#include <precomp.h>
#include "bitsfixup.h"
Include dependency graph for mktime.c:

Go to the source code of this file.

Macros

#define MAX_32BIT_TIME   0xFFFFFFFFULL
 

Functions

__time64_t mktime_worker (struct tm *ptm, int utc)
 
_mkgmtime
time_t _mkgmtime (struct tm *ptm)
 
time_t mktime (struct tm *ptm)
 
__time32_t _mkgmtime32 (struct tm *ptm)
 
__time32_t _mktime32 (struct tm *ptm)
 
__time64_t _mkgmtime64 (struct tm *ptm)
 
__time64_t _mktime64 (struct tm *ptm)
 

Variables

static int g_monthdays [13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}
 

Macro Definition Documentation

◆ MAX_32BIT_TIME

#define MAX_32BIT_TIME   0xFFFFFFFFULL

Definition at line 11 of file mktime.c.

Function Documentation

◆ _mkgmtime()

time_t _mkgmtime ( struct tm ptm)

Definition at line 114 of file mktime.c.

115 {
116  __time64_t time = mktime_worker(ptm, 1);
117  return (time_t)((time > MAX_32BIT_TIME) ? -1 : time);
118 }
__u16 time
Definition: mkdosfs.c:366
#define MAX_32BIT_TIME
Definition: mktime.c:11
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16
__kernel_time_t time_t
Definition: linux.h:252
__MINGW_EXTENSION typedef __int64 __time64_t
Definition: crtdefs.h:364

◆ _mkgmtime32()

__time32_t _mkgmtime32 ( struct tm ptm)

Definition at line 128 of file mktime.c.

129 {
130  __time64_t time = mktime_worker(ptm, 1);
131  return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time);
132 }
long __time32_t
Definition: crtdefs.h:358
__u16 time
Definition: mkdosfs.c:366
#define MAX_32BIT_TIME
Definition: mktime.c:11
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16
__MINGW_EXTENSION typedef __int64 __time64_t
Definition: crtdefs.h:364

◆ _mkgmtime64()

__time64_t _mkgmtime64 ( struct tm ptm)

Definition at line 142 of file mktime.c.

143 {
144  return mktime_worker(ptm, 1);
145 }
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16

◆ _mktime32()

__time32_t _mktime32 ( struct tm ptm)

Definition at line 135 of file mktime.c.

136 {
137  __time64_t time = mktime_worker(ptm, 0);
138  return (__time32_t)((time > MAX_32BIT_TIME) ? -1 : time);
139 }
long __time32_t
Definition: crtdefs.h:358
__u16 time
Definition: mkdosfs.c:366
#define MAX_32BIT_TIME
Definition: mktime.c:11
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16
__MINGW_EXTENSION typedef __int64 __time64_t
Definition: crtdefs.h:364

◆ _mktime64()

__time64_t _mktime64 ( struct tm ptm)

Definition at line 148 of file mktime.c.

149 {
150  return mktime_worker(ptm, 0);
151 }
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16

◆ mktime()

time_t mktime ( struct tm ptm)

Definition at line 121 of file mktime.c.

122 {
123  __time64_t time = mktime_worker(ptm, 0);
124  return (time_t)((time > MAX_32BIT_TIME) ? -1 : time);
125 }
__u16 time
Definition: mkdosfs.c:366
#define MAX_32BIT_TIME
Definition: mktime.c:11
__time64_t mktime_worker(struct tm *ptm, int utc)
Definition: mktime.c:16
__kernel_time_t time_t
Definition: linux.h:252
__MINGW_EXTENSION typedef __int64 __time64_t
Definition: crtdefs.h:364

Referenced by main().

◆ mktime_worker()

__time64_t mktime_worker ( struct tm ptm,
int  utc 
)

Definition at line 16 of file mktime.c.

17 {
18  struct tm *ptm2;
20  int mons, years, leapyears;
22  DWORD ret;
23 
24  /* Normalize year and month */
25  if (ptm->tm_mon < 0)
26  {
27  mons = -ptm->tm_mon - 1;
28  ptm->tm_year -= 1 + mons / 12;
29  ptm->tm_mon = 11 - (mons % 12);
30  }
31  else if (ptm->tm_mon > 11)
32  {
33  mons = ptm->tm_mon;
34  ptm->tm_year += (mons / 12);
35  ptm->tm_mon = mons % 12;
36  }
37 
38  /* Is it inside margins */
39  if (ptm->tm_year < 70 || ptm->tm_year > 139) // FIXME: max year for 64 bits
40  {
41  return -1;
42  }
43 
44  years = ptm->tm_year - 70;
45 
46  /* Number of leapyears passed since 1970 */
47  leapyears = (years + 1) / 4;
48 
49  /* Calculate days up to 1st of Jan */
50  time = years * 365 + leapyears;
51 
52  /* Calculate days up to 1st of month */
53  time += g_monthdays[ptm->tm_mon];
54 
55  /* Check if we need to add a leap day */
56  if (((years + 2) % 4) == 0)
57  {
58  if (ptm->tm_mon > 2)
59  {
60  time++;
61  }
62  }
63 
64  time += ptm->tm_mday - 1;
65 
66  time *= 24;
67  time += ptm->tm_hour;
68 
69  time *= 60;
70  time += ptm->tm_min;
71 
72  time *= 60;
73  time += ptm->tm_sec;
74 
75  if (time < 0)
76  {
77  return -1;
78  }
79 
80  /* Finally get normalized tm struct */
81  ptm2 = _gmtime64(&time);
82  if (!ptm2)
83  {
84  return -1;
85  }
86  *ptm = *ptm2;
87 
88  /* Finally adjust by the difference to GMT in seconds */
91  {
92  time += tzi.Bias * 60;
93  }
94 
95  return time;
96 }
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
int tm_min
Definition: time.h:78
int tm_mday
Definition: time.h:80
#define TIME_ZONE_ID_INVALID
Definition: winbase.h:283
int tm_year
Definition: time.h:82
__u16 time
Definition: mkdosfs.c:366
int tm_mon
Definition: time.h:81
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
Definition: time.h:76
_CRTIMP struct tm *__cdecl _gmtime64(_In_ const __time64_t *_Time)
int tm_sec
Definition: time.h:77
int tm_hour
Definition: time.h:79
__MINGW_EXTENSION typedef __int64 __time64_t
Definition: crtdefs.h:364
static int g_monthdays[13]
Definition: mktime.c:13

Referenced by _mkgmtime(), _mkgmtime32(), _mkgmtime64(), _mktime32(), _mktime64(), and mktime().

Variable Documentation

◆ g_monthdays

int g_monthdays[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}
static

Definition at line 13 of file mktime.c.

Referenced by mktime_worker().