ReactOS 0.4.15-dev-7958-gcd0bb1a
gmtime.c File Reference
#include <precomp.h>
Include dependency graph for gmtime.c:

Go to the source code of this file.

Functions

struct tm_gmtime_worker (struct tm *ptm, __time64_t time, int do_dst)
 
struct tm_gmtime64 (const __time64_t *ptime)
 
errno_t _gmtime64_s (struct tm *ptm, const __time64_t *ptime)
 
struct tm_gmtime32 (const __time32_t *ptime)
 
errno_t _gmtime32_s (struct tm *ptm, const __time32_t *ptime)
 
struct tmgmtime (const time_t *ptime)
 

Variables

unsigned int g_monthdays [13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}
 
unsigned int g_lpmonthdays [13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}
 

Function Documentation

◆ _gmtime32()

struct tm * _gmtime32 ( const __time32_t ptime)

Definition at line 153 of file gmtime.c.

154{
155 __time64_t time64;
156
157 if (!ptime)
158 return NULL;
159 time64 = *ptime;
160 return _gmtime64(&time64);
161}
#define NULL
Definition: types.h:112
struct tm * _gmtime64(const __time64_t *ptime)
Definition: gmtime.c:104

◆ _gmtime32_s()

errno_t _gmtime32_s ( struct tm ptm,
const __time32_t ptime 
)

Definition at line 164 of file gmtime.c.

167{
168 __time64_t time = *ptime;
169 if (!ptm)
170 {
172 return ERROR_BAD_COMMAND;
173 }
174
175 if (!ptime)
176 {
177 MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
178 return ERROR_BAD_COMMAND;
179 }
180
181 _gmtime_worker(ptm, time, 0);
182
183 return ERROR_SUCCESS;
184}
#define ERROR_SUCCESS
Definition: deptool.c:10
struct tm * _gmtime_worker(struct tm *ptm, __time64_t time, int do_dst)
Definition: gmtime.c:14
__u16 time
Definition: mkdosfs.c:8
#define MSVCRT_INVALID_PMT(x)
Definition: mbstowcs_s.c:25
#define ERROR_BAD_COMMAND
Definition: winerror.h:125

◆ _gmtime64()

struct tm * _gmtime64 ( const __time64_t *  ptime)

Definition at line 104 of file gmtime.c.

105{
107
108 /* Validate parameters */
109 if (!ptime || *ptime < 0)
110 {
111 return NULL;
112 }
113
114 if(!data->time_buffer)
115 data->time_buffer = malloc(sizeof(struct tm));
116
117 /* Use _gmtime_worker to do the real work */
118 return _gmtime_worker(data->time_buffer, *ptime, 0);
119}
#define malloc
Definition: debug_ros.c:4
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
Definition: time.h:68

Referenced by _gmtime32(), gmtime(), and mktime_worker().

◆ _gmtime64_s()

errno_t _gmtime64_s ( struct tm ptm,
const __time64_t *  ptime 
)

Definition at line 122 of file gmtime.c.

125{
126 __time64_t time;
127
128 if (!ptm)
129 {
131 return ERROR_BAD_COMMAND;
132 }
133
134 if (!ptime)
135 {
136 MSVCRT_INVALID_PMT("ptime == NULL", ERROR_BAD_COMMAND);
137 return ERROR_BAD_COMMAND;
138 }
139
140 time = *ptime;
141
142 _gmtime_worker(ptm, time, 0);
143
144 return ERROR_SUCCESS;
145}

Referenced by ATL::CTime::FormatGmt(), ATL::CTime::GetAsDBTIMESTAMP(), ATL::CTime::GetAsSystemTime(), and ATL::CTime::GetGmtTm().

◆ _gmtime_worker()

struct tm * _gmtime_worker ( struct tm ptm,
__time64_t  time,
int  do_dst 
)

Definition at line 14 of file gmtime.c.

15{
16 unsigned int days, daystoyear, dayinyear, leapdays, leapyears, years, month;
17 unsigned int secondinday, secondinhour;
18 unsigned int *padays;
19
20 if (time < 0)
21 {
22 return 0;
23 }
24
25 /* Divide into date and time */
26 days = (unsigned int)(time / SECONDSPERDAY);
27 secondinday = time % SECONDSPERDAY;
28
29 /* Shift to days from 1.1.1601 */
30 days += DIFFDAYS;
31
32 /* Calculate leap days passed till today */
33 leapdays = leapdays_passed(days);
34
35 /* Calculate number of full leap years passed */
36 leapyears = leapyears_passed(days);
37
38 /* Are more leap days passed than leap years? */
39 if (leapdays > leapyears)
40 {
41 /* Yes, we're in a leap year */
42 padays = g_lpmonthdays;
43 }
44 else
45 {
46 /* No, normal year */
47 padays = g_monthdays;
48 }
49
50 /* Calculate year */
51 years = (days - leapdays) / 365;
52 ptm->tm_year = years - 299;
53
54 /* Calculate number of days till 1.1. of this year */
55 daystoyear = years * 365 + leapyears;
56
57 /* Calculate the day in this year */
58 dayinyear = days - daystoyear;
59
60 /* Shall we do DST corrections? */
61 ptm->tm_isdst = 0;
62 if (do_dst)
63 {
64 int yeartime = dayinyear * SECONDSPERDAY + secondinday ;
65 if (yeartime >= dst_begin && yeartime <= dst_end) // FIXME! DST in winter
66 {
67 time -= _dstbias;
68 days = (unsigned int)(time / SECONDSPERDAY + DIFFDAYS);
69 dayinyear = days - daystoyear;
70 ptm->tm_isdst = 1;
71 }
72 }
73
74 ptm->tm_yday = dayinyear;
75
76 /* dayinyear < 366 => terminates with i <= 11 */
77 for (month = 0; dayinyear >= padays[month+1]; month++)
78 ;
79
80 /* Set month and day in month */
81 ptm->tm_mon = month;
82 ptm->tm_mday = 1 + dayinyear - padays[month];
83
84 /* Get weekday */
85 ptm->tm_wday = (days + 1) % 7;
86
87 /* Calculate hour and second in hour */
88 ptm->tm_hour = secondinday / SECONDSPERHOUR;
89 secondinhour = secondinday % SECONDSPERHOUR;
90
91 /* Calculate minute and second */
92 ptm->tm_min = secondinhour / 60;
93 ptm->tm_sec = secondinhour % 60;
94
95 return ptm;
96}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
static const WCHAR month[12][4]
Definition: session.c:2150
unsigned int g_lpmonthdays[13]
Definition: gmtime.c:11
unsigned int g_monthdays[13]
Definition: gmtime.c:10
static __inline long leapdays_passed(long days)
Definition: time.h:43
#define SECONDSPERDAY
Definition: time.h:8
long dst_begin
Definition: timezone.c:16
long dst_end
Definition: timezone.c:17
#define SECONDSPERHOUR
Definition: time.h:9
#define DIFFDAYS
Definition: time.h:2
static __inline long leapyears_passed(long days)
Definition: time.h:31
long _dstbias
Definition: timezone.c:62
int tm_mon
Definition: time.h:73
int tm_year
Definition: time.h:74
int tm_hour
Definition: time.h:71
int tm_sec
Definition: time.h:69
int tm_isdst
Definition: time.h:77
int tm_yday
Definition: time.h:76
int tm_mday
Definition: time.h:72
int tm_min
Definition: time.h:70
int tm_wday
Definition: time.h:75

Referenced by _gmtime32_s(), _gmtime64(), and _gmtime64_s().

◆ gmtime()

struct tm * gmtime ( const time_t ptime)

Definition at line 192 of file gmtime.c.

193{
194 __time64_t time64;
195
196 if (!ptime)
197 return NULL;
198 time64 = *ptime;
199 return _gmtime64(&time64);
200}

Variable Documentation

◆ g_lpmonthdays

unsigned int g_lpmonthdays[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}

Definition at line 11 of file gmtime.c.

Referenced by _gmtime_worker().

◆ g_monthdays

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

Definition at line 10 of file gmtime.c.

Referenced by _gmtime_worker().