wrowe 01/04/02 14:54:02
Modified: time/win32 time.c
include/arch/win32 atime.h
Log:
REVIEW Req'd ... solve the implode/explode discrepancy, but I hacked this
at 40,000 ft, and my brain was not altogether there. This merits discuss
at the Hackathon
Revision Changes Path
1.22 +19 -30 apr/time/win32/time.c
Index: time.c
===================================================================
RCS file: /home/cvs/apr/time/win32/time.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- time.c 2001/03/31 07:57:44 1.21
+++ time.c 2001/04/02 21:53:59 1.22
@@ -62,44 +62,20 @@
#include <string.h>
#include <winbase.h>
-/* Number of micro-seconds between the beginning of the Windows epoch
- * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
- */
-#define APR_DELTA_EPOCH_IN_USEC 11644473600000000;
-
-void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
-{
- /* Convert FILETIME one 64 bit number so we can work with it. */
- *result = input->dwHighDateTime;
- *result = (*result) << 32;
- *result |= input->dwLowDateTime;
- *result /= 10; /* Convert from 100 nano-sec periods to micro-seconds.
*/
- *result -= APR_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to
Unix epoch */
- return;
-}
-
-void AprTimeToFileTime(LPFILETIME pft, apr_time_t t)
-{
- LONGLONG ll;
- t += APR_DELTA_EPOCH_IN_USEC;
- ll = t * 10;
- pft->dwLowDateTime = (DWORD)ll;
- pft->dwHighDateTime = (DWORD) (ll >> 32);
- 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)
+static void SystemTimeToAprExpTime(apr_exploded_time_t *xt, SYSTEMTIME *tm,
BOOL lt)
{
TIME_ZONE_INFORMATION tz;
DWORD rc;
static const int dayoffset[12] =
{0, 31, 59, 90, 120, 151, 182, 212, 243, 273, 304, 334};
+ /* XXX: this is a looser - can't forefit precision like this
+ */
xt->tm_usec = tm->wMilliseconds * 1000;
xt->tm_sec = tm->wSecond;
xt->tm_min = tm->wMinute;
@@ -116,6 +92,12 @@
if (IsLeapYear(tm->wYear) && (xt->tm_yday > 58))
xt->tm_yday++;
+ if (!lt) {
+ xt->tm_isdst = 0;
+ xt->tm_gmtoff = 0;
+ return;
+ }
+
rc = GetTimeZoneInformation(&tz);
switch (rc) {
case TIME_ZONE_ID_UNKNOWN:
@@ -161,7 +143,8 @@
SYSTEMTIME st;
AprTimeToFileTime(&ft, input);
FileTimeToSystemTime(&ft, &st);
- SystemTimeToAprExpTime(result, &st);
+ SystemTimeToAprExpTime(result, &st, 0);
+ result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
return APR_SUCCESS;
}
@@ -174,7 +157,8 @@
AprTimeToFileTime(&ft, input);
FileTimeToLocalFileTime(&ft, &localft);
FileTimeToSystemTime(&localft, &st);
- SystemTimeToAprExpTime(result, &st);
+ SystemTimeToAprExpTime(result, &st, 1);
+ result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
return APR_SUCCESS;
}
@@ -239,6 +223,8 @@
apr_os_imp_time_t **ostime,
apr_pool_t *cont)
{
+ /* XXX: sanity failure, what is file time, gmt or local ?
+ */
FileTimeToAprTime(aprtime, *ostime);
return APR_SUCCESS;
}
@@ -247,7 +233,10 @@
apr_os_exp_time_t **ostime,
apr_pool_t *cont)
{
- SystemTimeToAprExpTime(aprtime, *ostime);
+ /* XXX: sanity failure, what is system time, gmt or local ?
+ * Assume local for this moment.
+ */
+ SystemTimeToAprExpTime(aprtime, *ostime, 1);
return APR_SUCCESS;
}
1.11 +30 -3 apr/include/arch/win32/atime.h
Index: atime.h
===================================================================
RCS file: /home/cvs/apr/include/arch/win32/atime.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- atime.h 2001/02/16 04:15:52 1.10
+++ atime.h 2001/04/02 21:54:01 1.11
@@ -64,9 +64,36 @@
apr_time_t currtime;
SYSTEMTIME *explodedtime;
};
-
-void FileTimeToAprTime(apr_time_t *atime, FILETIME *ft);
-void AprTimeToFileTime(LPFILETIME pft, apr_time_t t);
+
+
+/* Number of micro-seconds between the beginning of the Windows epoch
+ * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
+ */
+#define APR_DELTA_EPOCH_IN_USEC APR_TIME_C(11644473600000000);
+
+
+__inline void FileTimeToAprTime(apr_time_t *result, FILETIME *input)
+{
+ /* Convert FILETIME one 64 bit number so we can work with it. */
+ *result = input->dwHighDateTime;
+ *result = (*result) << 32;
+ *result |= input->dwLowDateTime;
+ *result /= 10; /* Convert from 100 nano-sec periods to micro-seconds.
*/
+ *result -= APR_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to
Unix epoch */
+ return;
+}
+
+
+__inline void AprTimeToFileTime(LPFILETIME pft, apr_time_t t)
+{
+ LONGLONG ll;
+ t += APR_DELTA_EPOCH_IN_USEC;
+ ll = t * 10;
+ pft->dwLowDateTime = (DWORD)ll;
+ pft->dwHighDateTime = (DWORD) (ll >> 32);
+ return;
+}
+
#endif /* ! ATIME_H */