fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / config / gen / platform / win32 / time.c
blob5ab00d91531364d56bc088fb2d628f91b9c8d275
1 /*
2 * $Id$
3 * Copyright (C) 2004-2006, Parrot Foundation.
4 */
6 /*
8 =head1 NAME
10 config\gen\platform\win32\time.c
12 =head1 DESCRIPTION
14 Provides access to system time functions for Win32 platforms.
16 =head2 Functions
18 =over 4
20 =cut
24 #include <time.h>
28 =item C<INTVAL Parrot_intval_time(void)>
30 Returns the current time as an INTVAL
32 =cut
36 INTVAL
37 Parrot_intval_time(void)
39 #if defined(_MSC_VER) && _MSC_VER >= 1400
40 # ifdef _WIN64
41 return (INTVAL)_time64(NULL);
42 # else
43 return _time32(NULL);
44 # endif
45 #else
46 return time(NULL);
47 #endif
52 =item C<FLOATVAL Parrot_floatval_time(void)>
54 Returns the current time as a FLOATVAL.
56 =cut
60 FLOATVAL
61 Parrot_floatval_time(void)
63 SYSTEMTIME sysTime;
64 /* 100 ns ticks since 1601-01-01 00:00:00 */
65 FILETIME fileTime;
66 LARGE_INTEGER i;
68 GetSystemTime(&sysTime);
69 SystemTimeToFileTime(&sysTime, &fileTime);
70 /* Documented as the way to get a 64 bit from a FILETIME. */
71 memcpy(&i, &fileTime, sizeof (LARGE_INTEGER));
73 /* FILETIME uses 100ns steps since 1601-01-01 00:00:00 as epoch.
74 * We'd like 1 second steps since 1970-01-01 00:00:00.
75 * To get there, divide by 10,000,000 to get from 100ns steps to seconds.
76 * Then subtract the seconds between 1601 and 1970, i.e. 11,644,473,600.
78 return (FLOATVAL)i.QuadPart / 10000000.0 - 11644473600.0;
84 =item C<void Parrot_sleep(unsigned int seconds)>
86 Sleeps for C<seconds> seconds.
88 =cut
92 void
93 Parrot_sleep(unsigned int seconds)
95 Sleep(seconds * 1000);
100 =item C<void Parrot_usleep(unsigned int microseconds)>
102 Sleep for at least the specified number of microseconds (millionths of a
103 second).
105 =cut
109 void
110 Parrot_usleep(unsigned int microseconds)
112 Sleep(microseconds / 1000);
117 =item C<struct tm * Parrot_gmtime_r(const time_t *t, struct tm *tm)>
119 Returns a C<time_t> structure for the current Greenwich Mean Time.
121 =cut
125 PARROT_EXPORT
126 struct tm *
127 Parrot_gmtime_r(const time_t *t, struct tm *tm)
129 *tm = *gmtime(t);
130 return tm;
135 =item C<struct tm * Parrot_localtime_r(const time_t *t, struct tm *tm)>
137 Returns a C<time_t> struct for the current local time.
139 =cut
143 PARROT_EXPORT
144 struct tm *
145 Parrot_localtime_r(const time_t *t, struct tm *tm)
147 *tm = *localtime(t);
148 return tm;
153 =item C<char* Parrot_asctime_r(const struct tm *tm, char *buffer)>
155 Returns an ASCII representation of the C<struct tm>. Puts it in the
156 character array C<buffer>.
158 =cut
162 PARROT_EXPORT
163 char*
164 Parrot_asctime_r(const struct tm *tm, char *buffer)
166 static const char wday_name[7][4] =
167 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
168 static const char mon_name[12][4] =
169 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
170 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
172 sprintf(buffer, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
173 wday_name[tm->tm_wday],
174 mon_name[tm->tm_mon],
175 tm->tm_mday,
176 tm->tm_hour,
177 tm->tm_min,
178 tm->tm_sec,
179 1900 + tm->tm_year);
181 return buffer;
186 =back
188 =cut
193 * Local variables:
194 * c-file-style: "parrot"
195 * End:
196 * vim: expandtab shiftwidth=4: