Skip to content

Commit

Permalink
Merge pull request #4584 from MartinNowak/fixWinTZTranslations
Browse files Browse the repository at this point in the history
fix test failure for updated Windows TZs
  • Loading branch information
WalterBright committed Jul 9, 2016
2 parents 02d1aed + aa88e7b commit 01eb06b
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions std/datetime.d
Expand Up @@ -122,6 +122,12 @@ version(Windows)
import core.sys.windows.windows;
import core.sys.windows.winsock2;
import std.windows.registry;

// Uncomment and run unittests to print missing Windows TZ translations.
// Please subscribe to Microsoft Daylight Saving Time & Time Zone Blog
// (https://blogs.technet.microsoft.com/dst2007/) if you feel responsible
// for updating the translations.
// version = UpdateWindowsTZTranslations;
}
else version(Posix)
{
Expand Down Expand Up @@ -27270,21 +27276,13 @@ public:
{
import std.array : appender;
import std.algorithm : startsWith, sort;
import std.format : format;

auto windowsNames = WindowsTimeZone.getInstalledTZNames();
auto retval = appender!(string[])();

foreach(winName; windowsNames)
{
auto tzName = windowsTZNameToTZDatabaseName(winName);

version(unittest)
{
import std.string;
assert(tzName !is null, format("TZName which is missing: %s", winName));
}

if(tzName !is null && tzName.startsWith(subName))
retval.put(tzName);
}
Expand Down Expand Up @@ -30660,11 +30658,15 @@ string tzDatabaseNameToWindowsTZName(string tzName) @safe pure nothrow @nogc
}
}

version(Windows) unittest
version(Windows) version(UpdateWindowsTZTranslations) unittest
{
import std.format : format;
import std.stdio : stderr;

foreach(tzName; TimeZone.getInstalledTZNames())
assert(tzDatabaseNameToWindowsTZName(tzName) !is null, format("TZName which failed: %s", tzName));
{
if (tzDatabaseNameToWindowsTZName(tzName) is null)
stderr.writeln("Missing TZName to Windows translation: ", tzName);
}
}


Expand Down Expand Up @@ -30818,11 +30820,15 @@ string windowsTZNameToTZDatabaseName(string tzName) @safe pure nothrow @nogc
}
}

version(Windows) unittest
version(Windows) version(UpdateWindowsTZTranslations) unittest
{
import std.format : format;
foreach(tzName; WindowsTimeZone.getInstalledTZNames())
assert(windowsTZNameToTZDatabaseName(tzName) !is null, format("TZName which failed: %s", tzName));
import std.stdio : stderr;

foreach(winName; WindowsTimeZone.getInstalledTZNames())
{
if (windowsTZNameToTZDatabaseName(winName) is null)
stderr.writeln("Missing Windows to TZName translation: ", winName);
}
}


Expand Down

0 comments on commit 01eb06b

Please sign in to comment.