2 * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
3 * PROJECT: ReactOS CRT library
4 * FILE: lib/sdk/crt/time/timezone.c
5 * PURPOSE: Implementation of time zone functions
6 * PROGRAMERS: Timo Kreuzer
12 /* buffers must hold 64 characters! */
13 static char tz_name
[64] = "PST";
14 static char tz_dst_name
[64] = "PDT";
19 /******************************************************************************
27 /******************************************************************************
32 /******************************************************************************
34 * \brief Returns a pointer to the _daylight variable;
42 /******************************************************************************
46 long _timezone
= 28800;
48 /******************************************************************************
50 * \brief Returns a pointer to the _timezone variable;
58 /******************************************************************************
64 /******************************************************************************
66 * \brief Returns a pointer to the _dstbias variable;
74 /******************************************************************************
76 * \brief Returns a pointer to the _tzname buffer;
84 /******************************************************************************
86 * \brief Initializes the variables _daylight, _timezone, and _tzname from the
87 * "TZ" environment variable if available or else by calling
88 * GetTimeZoneInformation.
89 * \sa http://msdn.microsoft.com/en-us/library/90s5c885.aspx
101 /* Try to read the timezone from environment */
103 if (str
&& str
[0] != 0)
105 long hour
= 0, min
= 0, sec
= 0;
106 size_t len
= strnlen(str
, 16);
113 /* Copy timezone name */
114 strncpy(tz_name
, str
, 3);
120 if (*str
== '+' || *str
== '-')
122 sign
= *str
== '-' ? -1 : 1;
131 while (*str
!= 0 && *str
!= ':') str
++;
132 if (*str
== 0) break;
136 while (*str
!= 0 && *str
!= ':') str
++;
137 if (*str
== 0) break;
141 while (*str
!= 0 && *str
<= '9') str
++;
142 if (*str
== 0) break;
145 strncpy(tz_dst_name
, str
, 3);
147 // FIXME: set dst_begin etc
149 /* We are finished */
153 _timezone
= sign
* (((hour
* 60) + min
) * 60 + sec
);
158 TIME_ZONE_INFORMATION tzi
;
161 ret
= GetTimeZoneInformation(&tzi
);
162 if (ret
== TIME_ZONE_ID_INVALID
)
167 ret
= WideCharToMultiByte(CP_ACP
,
176 ret
= WideCharToMultiByte(CP_ACP
,
185 _timezone
= tzi
.Bias
* 60;
187 if (tzi
.DaylightDate
.wMonth
)
192 _dstbias
= (tzi
.DaylightBias
- tzi
.StandardBias
) * 60;
194 _tm
.tm_mon
= tzi
.DaylightDate
.wMonth
- 1;
195 _tm
.tm_mday
= tzi
.DaylightDate
.wDay
;
196 _tm
.tm_hour
= tzi
.DaylightDate
.wHour
;
197 _tm
.tm_min
= tzi
.DaylightDate
.wMinute
;
198 _tm
.tm_sec
= tzi
.DaylightDate
.wSecond
;
199 dst_begin
= (long)_mkgmtime(&_tm
);
200 _tm
.tm_mon
= tzi
.StandardDate
.wMonth
- 1;
201 _tm
.tm_mday
= tzi
.StandardDate
.wDay
;
202 _tm
.tm_hour
= tzi
.StandardDate
.wHour
;
203 _tm
.tm_min
= tzi
.StandardDate
.wMinute
;
204 _tm
.tm_sec
= tzi
.StandardDate
.wSecond
;
205 dst_end
= (long)_mkgmtime(&_tm
);
217 /*********************************************************************
218 * _get_tzname (MSVCRT.@)
220 int CDECL
_get_tzname(size_t *ret
, char *buf
, size_t bufsize
, int index
)
227 str_timezone
= tz_name
;
231 str_timezone
= tz_dst_name
;
239 if (!ret
|| (!buf
&& (bufsize
> 0)) || (buf
&& !bufsize
))
245 *ret
= strlen(str_timezone
) + 1;
249 strncpy(buf
, str_timezone
, bufsize
);