Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit 5c2a7e4

Browse files
Add a Win32 implementation of MCDateExecGetUniversalTime
1 parent 166dafe commit 5c2a7e4

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

libscript/src/module-date.cpp

100644100755
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919
#include <foundation-auto.h>
2020

2121
#include <time.h>
22-
#include <sys/time.h>
22+
23+
#ifndef _WINDOWS
24+
# include <sys/time.h>
25+
#else
26+
# include <windows.h>
27+
#endif
2328

2429
/* Windows doesn't have localtime_r(), but it does have an equivalent
2530
* function with the arguments in the opposite order! */
@@ -56,8 +61,23 @@ MCDateExecGetLocalDate (MCProperListRef & r_datetime)
5661
extern "C" MC_DLLEXPORT void
5762
MCDateExecGetUniversalTime (double& r_time)
5863
{
64+
#ifndef _WINDOWS
5965
struct timeval tv;
6066

6167
gettimeofday(&tv, NULL);
6268
r_time = tv.tv_sec + (double)tv.tv_usec / 1000000.0;
69+
#else
70+
SYSTEMTIME t_localtime;
71+
FILETIME t_filetime;
72+
GetLocalTime(&t_localtime);
73+
SystemTimeToFileTime(&t_localtime, &t_filetime);
74+
75+
// The Win32 filetime counts 100ns intervals since 1st Jan 1601
76+
uint64_t t_time_win32;
77+
double t_time_unix;
78+
t_time_win32 = (uint64_t(t_filetime.dwHighDateTime) << 32) | t_filetime.dwLowDateTime;
79+
t_time_unix = (double(t_time_win32) / 10000000.0) - 11644473600.0;
80+
81+
r_time = t_time_unix;
82+
#endif
6383
}

0 commit comments

Comments
 (0)