Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
andralex committed Dec 21, 2017
1 parent fa94656 commit d73e2b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions std/datetime/systime.d
Original file line number Diff line number Diff line change
Expand Up @@ -2299,13 +2299,13 @@ public:
@system unittest
{
import std.conv : to;
import std.datetime.timezone : clearTZEnvVar, setTZEnvVar;
import core.time;

version(Posix)
{
scope(exit) clearTZEnvVar();
import std.datetime.timezone : clearTZEnvVar, setTZEnvVar;
setTZEnvVar("America/Los_Angeles");
scope(exit) clearTZEnvVar();
}

{
Expand Down Expand Up @@ -9301,6 +9301,7 @@ else version(Windows)

auto dt = DateTime(st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

import core.time : msecs;
return SysTime(dt, msecs(st.wMilliseconds), tz);
}

Expand All @@ -9310,7 +9311,7 @@ else version(Windows)
SYSTEMTIME st = void;
GetSystemTime(&st);
auto converted = SYSTEMTIMEToSysTime(&st, UTC());

import core.time : abs;
assert(abs((converted - sysTime)) <= dur!"seconds"(2));
}

Expand Down Expand Up @@ -9387,6 +9388,7 @@ else version(Windows)

auto converted = FILETIMEToSysTime(&ft);

import core.time : abs;
assert(abs((converted - sysTime)) <= dur!"seconds"(2));
}

Expand Down
7 changes: 7 additions & 0 deletions std/datetime/timezone.d
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,7 @@ else version(Windows)

return new immutable WindowsTimeZone(name, tzInfo);
}
import std.datetime.date : DateTimeException;
throw new DateTimeException(format("Failed to find time zone: %s", name));
}

Expand Down Expand Up @@ -3026,6 +3027,7 @@ else version(Windows)

auto tzNames = getInstalledTZNames();

import std.datetime.date : DateTimeException;
foreach (tzName; tzNames)
assertNotThrown!DateTimeException(testWTZSuccess(tzName));
}
Expand All @@ -3040,11 +3042,13 @@ else version(Windows)
if (tzInfo.DaylightDate.wMonth == 0)
return false;

import std.datetime.date : DateTime, Month;
auto utcDateTime = cast(DateTime) SysTime(stdTime, UTC());

//The limits of what SystemTimeToTzSpecificLocalTime will accept.
if (utcDateTime.year < 1601)
{
import std.datetime.date : Month;
if (utcDateTime.month == Month.feb && utcDateTime.day == 29)
utcDateTime.day = 28;
utcDateTime.year = 1601;
Expand Down Expand Up @@ -3109,6 +3113,7 @@ else version(Windows)
TIME_ZONE_INFORMATION tzInfo;
GetTimeZoneInformation(&tzInfo);

import std.datetime.date : DateTime;
foreach (year; [1600, 1601, 30_827, 30_828])
WindowsTimeZone._dstInEffect(&tzInfo, SysTime(DateTime(year, 1, 1)).stdTime);
}
Expand All @@ -3129,6 +3134,7 @@ else version(Windows)
{
try
{
import std.datetime.date : DateTime, Month;
bool dstInEffectForLocalDateTime(DateTime localDateTime)
{
// The limits of what SystemTimeToTzSpecificLocalTime will accept.
Expand Down Expand Up @@ -3193,6 +3199,7 @@ else version(Windows)
return false;
}

import std.datetime.date : DateTime;
auto localDateTime = cast(DateTime) SysTime(adjTime, UTC());
auto localDateTimeBefore = localDateTime - dur!"hours"(1);
auto localDateTimeAfter = localDateTime + dur!"hours"(1);
Expand Down

0 comments on commit d73e2b2

Please sign in to comment.