time.c revision 6ebd91a0c7f4c62a501b67adce4a6800d8b7dfac
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
9cee5bb02863bf191e12cd4297adabf1971020deAutomatic Updater * Copyright (C) 2004, 2006-2008 Internet Systems Consortium, Inc. ("ISC")
fcb54ce0a4f7377486df5bec83b3aa4711bf4131Mark Andrews * Copyright (C) 1998-2001, 2003 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * Permission to use, copy, modify, and/or distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9a859983d7059a6eb9c877c1d2ac6a3a5b7170f7Evan Hunt/* $Id: time.c,v 1.45 2008/08/29 23:47:22 tbox Exp $ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <config.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <errno.h>
de153390f5a1f6d4fa86af91d4cae772d9846ca0Mark Andrews#include <limits.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <stddef.h>
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington#include <stdlib.h>
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington#include <string.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <time.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson#include <windows.h>
25a66b4e41e2b0a2af4840749bac80ae78c678bfMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#include <isc/assertions.h>
21f1794606dce19928cf455029e173321f166380Mark Andrews#include <isc/time.h>
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews#include <isc/util.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence/*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * struct FILETIME uses "100-nanoseconds intervals".
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * NS / S = 1000000000 (10^9).
28b863e609ff2d97b78663b46894494cfa2ea411Mark Andrews * While it is reasonably obvious that this makes the needed
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * conversion factor 10^7, it is coded this way for additional clarity.
21825a8d005ccc2dfaf12889bf9eef3413555277Brian Wellington */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#define NS_PER_S 1000000000
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#define NS_INTERVAL 100
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define INTERVALS_PER_S (NS_PER_S / NS_INTERVAL)
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews#define UINT64_MAX _UI64_MAX
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews/***
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence *** Absolute Times
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews ***/
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic isc_time_t epoch = { { 0, 0 } };
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas GustafssonLIBISC_EXTERNAL_DATA isc_time_t *isc_time_epoch = &epoch;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews/***
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews *** Intervals
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews ***/
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsstatic isc_interval_t zero_interval = { 0 };
9ac7076ebad044afb15e9e2687e3696868778538Mark AndrewsLIBISC_EXTERNAL_DATA isc_interval_t *isc_interval_zero = &zero_interval;
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsvoid
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrewsisc_interval_set(isc_interval_t *i, unsigned int seconds,
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews unsigned int nanoseconds)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews{
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews REQUIRE(i != NULL);
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews REQUIRE(nanoseconds < NS_PER_S);
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews /*
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews * This rounds nanoseconds up not down.
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews */
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews i->interval = (LONGLONG)seconds * INTERVALS_PER_S
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence + (nanoseconds + NS_INTERVAL - 1) / NS_INTERVAL;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsisc_boolean_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_interval_iszero(const isc_interval_t *i) {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence REQUIRE(i != NULL);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence if (i->interval == 0)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (ISC_TRUE);
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (ISC_FALSE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencevoid
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_time_settoepoch(isc_time_t *t) {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence REQUIRE(t != NULL);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence t->absolute.dwLowDateTime = 0;
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence t->absolute.dwHighDateTime = 0;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence}
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_boolean_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceisc_time_isepoch(const isc_time_t *t) {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence REQUIRE(t != NULL);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence if (t->absolute.dwLowDateTime == 0 &&
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence t->absolute.dwHighDateTime == 0)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (ISC_TRUE);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (ISC_FALSE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_result_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsisc_time_now(isc_time_t *t) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews REQUIRE(t != NULL);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein GetSystemTimeAsFileTime(&t->absolute);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson return (ISC_R_SUCCESS);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson}
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafssonisc_result_t
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinisc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ULARGE_INTEGER i1;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater REQUIRE(t != NULL);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson REQUIRE(i != NULL);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence GetSystemTimeAsFileTime(&t->absolute);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.LowPart = t->absolute.dwLowDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.HighPart = t->absolute.dwHighDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_R_RANGE);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.QuadPart += i->interval;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont t->absolute.dwLowDateTime = i1.LowPart;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont t->absolute.dwHighDateTime = i1.HighPart;
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont return (ISC_R_SUCCESS);
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont}
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupont
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontint
9fe8cca06537c45375c1e1d36b82501caf0ae090Francis Dupontisc_time_compare(const isc_time_t *t1, const isc_time_t *t2) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence REQUIRE(t1 != NULL && t2 != NULL);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return ((int)CompareFileTime(&t1->absolute, &t2->absolute));
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence}
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence{
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ULARGE_INTEGER i1;
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington REQUIRE(t != NULL && i != NULL && result != NULL);
330705066b03f6ce0bc08a4bbfc5d2418038c68dBrian Wellington
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.LowPart = t->absolute.dwLowDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.HighPart = t->absolute.dwHighDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_R_RANGE);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.QuadPart += i->interval;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result->absolute.dwLowDateTime = i1.LowPart;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result->absolute.dwHighDateTime = i1.HighPart;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_R_SUCCESS);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence}
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_time_subtract(const isc_time_t *t, const isc_interval_t *i,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_time_t *result) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ULARGE_INTEGER i1;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence REQUIRE(t != NULL && i != NULL && result != NULL);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.LowPart = t->absolute.dwLowDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.HighPart = t->absolute.dwHighDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (i1.QuadPart < (unsigned __int64) i->interval)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_R_RANGE);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews i1.QuadPart -= i->interval;
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews result->absolute.dwLowDateTime = i1.LowPart;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result->absolute.dwHighDateTime = i1.HighPart;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (ISC_R_SUCCESS);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence}
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_uint64_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ULARGE_INTEGER i1, i2;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence LONGLONG i3;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence REQUIRE(t1 != NULL && t2 != NULL);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.LowPart = t1->absolute.dwLowDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i1.HighPart = t1->absolute.dwHighDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i2.LowPart = t2->absolute.dwLowDateTime;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i2.HighPart = t2->absolute.dwHighDateTime;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if (i1.QuadPart <= i2.QuadPart)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence return (0);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence /*
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence * Convert to microseconds.
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence i3 = (i1.QuadPart - i2.QuadPart) / 10;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews return (i3);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews}
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_uint32_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrenceisc_time_seconds(const isc_time_t *t) {
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson SYSTEMTIME st;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews /*
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * Convert the time to a SYSTEMTIME structure and the grab the
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews * milliseconds
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews */
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews FileTimeToSystemTime(&t->absolute, &st);
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews
c5223c9cb7c22620d5ee6611228673e95b48a270Mark Andrews return ((isc_uint32_t)(st.wMilliseconds / 1000));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsisc_uint32_t
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrewsisc_time_nanoseconds(const isc_time_t *t) {
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews SYSTEMTIME st;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews /*
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews * Convert the time to a SYSTEMTIME structure and the grab the
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews * milliseconds
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews */
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews FileTimeToSystemTime(&t->absolute, &st);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews return ((isc_uint32_t)(st.wMilliseconds * 1000000));
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews}
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrews
b6a0341bcb113e93bd0bc41a9f9a1fc117444da6Mark Andrewsvoid
aa05bbdef7f7827dde158dcc913f4dade84c8511Brian Wellingtonisc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) {
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews FILETIME localft;
23cb957a81a51a9656917ea98d0ae56b7abdcaccMark Andrews SYSTEMTIME st;
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews char DateBuf[50];
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews char TimeBuf[50];
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews static const char badtime[] = "99-Bad-9999 99:99:99.999";
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews REQUIRE(len > 0);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews if (FileTimeToLocalFileTime(&t->absolute, &localft) &&
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews FileTimeToSystemTime(&localft, &st)) {
78838d3e0cd62423c23de5503910e01884d2104bBrian Wellington GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "dd-MMM-yyyy",
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews DateBuf, 50);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER|
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews TIME_FORCE24HOURFORMAT, &st, NULL, TimeBuf, 50);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews snprintf(buf, len, "%s %s.%03u", DateBuf, TimeBuf,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews st.wMilliseconds);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews } else
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews snprintf(buf, len, badtime);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews}
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsvoid
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsisc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff SYSTEMTIME st;
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews char DateBuf[50];
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews char TimeBuf[50];
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews REQUIRE(len > 0);
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews if (FileTimeToSystemTime(&t->absolute, &st)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "ddd',', dd-MMM-yyyy",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews DateBuf, 50);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews GetTimeFormat(LOCALE_USER_DEFAULT,
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews TIME_NOTIMEMARKER | TIME_FORCE24HOURFORMAT,
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews &st, "hh':'mm':'ss", TimeBuf, 50);
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews snprintf(buf, len, "%s %s GMT", DateBuf, TimeBuf);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews buf[0] = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews