3 * @brief Time handling for Windows
10 * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved.
12 * This software is distributed under commercial and open source licenses.
13 * You may use the GPL open source license described below or you may acquire
14 * a commercial license from Mbedthis Software. You agree to be fully bound
15 * by the terms of either license. Consult the LICENSE.TXT distributed with
16 * this software for full details.
18 * This software is open source; you can redistribute it and/or modify it
19 * under the terms of the GNU General Public License as published by the
20 * Free Software Foundation; either version 2 of the License, or (at your
21 * option) any later version. See the GNU General Public License for more
22 * details at: http://www.mbedthis.com/downloads/gplLicense.html
24 * This program is distributed WITHOUT ANY WARRANTY; without even the
25 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 * This GPL license does NOT permit incorporating this software into
28 * proprietary programs. If you are unable to comply with the GPL, you must
29 * acquire a commercial license to use this software. Commercial licenses
30 * for this software and support services are available from Mbedthis
31 * Software at http://www.mbedthis.com
36 /********************************* Includes ***********************************/
44 /************************************ Code ************************************/
46 * Returns time in seconds and milliseconds. This is NOT time-of-day.
49 MprTime *mprGetTime(MprCtx ctx, MprTime *tp)
54 GetSystemTimeAsFileTime(&fileTime);
56 now = ((((int64) fileTime.dwHighDateTime) << BITS(uint)) +
57 ((int64) fileTime.dwLowDateTime));
60 * Convert from 100-nanosec units to milliseconds
65 * Adjust to be seconds since Jan 1 1970. Do this to be consistent with
66 * UNIX but not really required by the API definition.
68 base = ((UINT64(365) * 86400 * (1970 - 1601)) * 1000);
70 tp->sec = (uint) (now / 1000);
71 tp->msec = (uint) (now % 1000);
81 mprLog(ctx, 0, "TIME WENT BACKWARDS");
82 mprLog(ctx, 0, "start %Ld", start);
83 mprLog(ctx, 0, "now %Ld", now);
85 mprLog(ctx, 0, "getTime %Ld", now);
93 /******************************************************************************/
95 * Thread-safe wrapping of localtime
98 struct tm *mprLocaltime(MprCtx ctx, struct tm *timep, time_t *now)
102 tbuf = localtime(now);
104 mprGlobalUnlock(ctx);
109 /******************************************************************************/
111 * Thread-safe wrapping of gmtime
114 struct tm *mprGmtime(MprCtx ctx, time_t *now, struct tm *timep)
123 /******************************************************************************/
125 * Thread-safe wrapping of ctime
128 int mprCtime(MprCtx ctx, char *buf, int bufsize, const time_t *timer)
138 if ((int) strlen(cp) >= bufsize) {
139 mprStrcpy(buf, bufsize, "WONT FIT");
141 mprGlobalUnlock(ctx);
142 return MPR_ERR_WONT_FIT;
145 len = mprStrcpy(buf, bufsize, cp);
146 if (buf[len - 1] == '\n') {
150 mprGlobalUnlock(ctx);
155 /******************************************************************************/
157 * Thread-safe wrapping of asctime
160 int mprAsctime(MprCtx ctx, char *buf, int bufsize, const struct tm *timeptr)
166 cp = asctime(timeptr);
167 if ((int) strlen(cp) >= bufsize) {
169 mprGlobalUnlock(ctx);
170 return MPR_ERR_WONT_FIT;
172 mprStrcpy(buf, bufsize, cp);
173 mprGlobalUnlock(ctx);
178 /******************************************************************************/
190 * vim600: sw=4 ts=4 fdm=marker