summaryrefslogtreecommitdiff
path: root/lib/isc/win32/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/isc/win32/time.c')
-rw-r--r--lib/isc/win32/time.c63
1 files changed, 44 insertions, 19 deletions
diff --git a/lib/isc/win32/time.c b/lib/isc/win32/time.c
index aebf73d3121c..aafd70b124de 100644
--- a/lib/isc/win32/time.c
+++ b/lib/isc/win32/time.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2004, 2006-2008 Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004, 2006-2009 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 1998-2001, 2003 Internet Software Consortium.
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: time.c,v 1.48 2008/09/08 23:47:10 tbox Exp $ */
+/* $Id: time.c,v 1.52 2009/08/14 07:51:08 marka Exp $ */
#include <config.h>
@@ -226,28 +226,30 @@ isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) {
isc_uint32_t
isc_time_seconds(const isc_time_t *t) {
- SYSTEMTIME st;
+ SYSTEMTIME epoch = { 1970, 1, 4, 1, 0, 0, 0, 0 };
+ FILETIME temp;
+ ULARGE_INTEGER i1, i2;
+ LONGLONG i3;
- /*
- * Convert the time to a SYSTEMTIME structure and the grab the
- * milliseconds
- */
- FileTimeToSystemTime(&t->absolute, &st);
+ SystemTimeToFileTime(&epoch, &temp);
- return ((isc_uint32_t)(st.wMilliseconds / 1000));
+ i1.LowPart = t->absolute.dwLowDateTime;
+ i1.HighPart = t->absolute.dwHighDateTime;
+ i2.LowPart = temp.dwLowDateTime;
+ i2.HighPart = temp.dwHighDateTime;
+
+ i3 = (i1.QuadPart - i2.QuadPart) / 10000000;
+
+ return ((isc_uint32_t)i3);
}
isc_uint32_t
isc_time_nanoseconds(const isc_time_t *t) {
- SYSTEMTIME st;
-
- /*
- * Convert the time to a SYSTEMTIME structure and the grab the
- * milliseconds
- */
- FileTimeToSystemTime(&t->absolute, &st);
+ ULARGE_INTEGER i;
- return ((isc_uint32_t)(st.wMilliseconds * 1000000));
+ i.LowPart = t->absolute.dwLowDateTime;
+ i.HighPart = t->absolute.dwHighDateTime;
+ return ((isc_uint32_t)(i.QuadPart % 10000000) * 100);
}
void
@@ -280,10 +282,12 @@ isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
char DateBuf[50];
char TimeBuf[50];
+/* strftime() format: "%a, %d %b %Y %H:%M:%S GMT" */
+
REQUIRE(len > 0);
if (FileTimeToSystemTime(&t->absolute, &st)) {
- GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "ddd',', dd-MMM-yyyy",
- DateBuf, 50);
+ GetDateFormat(LOCALE_USER_DEFAULT, 0, &st,
+ "ddd',', dd-MMM-yyyy", DateBuf, 50);
GetTimeFormat(LOCALE_USER_DEFAULT,
TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
&st, "hh':'mm':'ss", TimeBuf, 50);
@@ -293,3 +297,24 @@ isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
buf[0] = 0;
}
}
+
+void
+isc_time_formatISO8601(const isc_time_t *t, char *buf, unsigned int len) {
+ SYSTEMTIME st;
+ char DateBuf[50];
+ char TimeBuf[50];
+
+/* strtime() format: "%Y-%m-%dT%H:%M:%SZ" */
+
+ REQUIRE(len > 0);
+ if (FileTimeToSystemTime(&t->absolute, &st)) {
+ GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyy-MM-dd",
+ DateBuf, 50);
+ GetTimeFormat(LOCALE_NEUTRAL,
+ TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
+ &st, "hh':'mm':'ss", TimeBuf, 50);
+ snprintf(buf, len, "%s%sZ", DateBuf, TimeBuf);
+ } else {
+ buf[0] = 0;
+ }
+}