Skip to content

Commit

Permalink
[release/5.0] Add backward compatibility file to timezone data compil…
Browse files Browse the repository at this point in the history
…ation (#43982)

* [wasm] Add backward compatibility file to timezone data compilation (#43786)

* Add backward file from iana to handle backward compatibility in tz data
* add tests to check for backwards compatibility

* include backward in downloaded files

* bumpd tzdb version to 2020d
  • Loading branch information
tqiu8 authored Nov 21, 2020
1 parent e7c0be8 commit 9ecbcd7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
AssemblyFile="$(CreateCreateWasmBundlesAssemblyPath)" />
<Target Condition="'$(TargetOS)' == 'Browser'" Name="LoadTimeZone" >
<PropertyGroup>
<TimeZoneDataVersion>2020a</TimeZoneDataVersion>
<TimeZoneDataVersion>2020d</TimeZoneDataVersion>
</PropertyGroup>
<DownloadTimeZoneData
InputDirectory="$(BundleDir)obj/data/input"
Expand Down
44 changes: 44 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,50 @@ public static void TestNameWithInvariantCulture()

}

[Theory]
[PlatformSpecific(TestPlatforms.Browser)]
[InlineData("America/Buenos_Aires", "America/Argentina/Buenos_Aires")]
[InlineData("America/Catamarca", "America/Argentina/Catamarca")]
[InlineData("America/Cordoba", "America/Argentina/Cordoba")]
[InlineData("America/Jujuy", "America/Argentina/Jujuy")]
[InlineData("America/Mendoza", "America/Argentina/Mendoza")]
[InlineData("America/Indianapolis", "America/Indiana/Indianapolis")]
public static void TestTimeZoneIdBackwardCompatibility(string oldId, string currentId)
{
TimeZoneInfo oldtz = TimeZoneInfo.FindSystemTimeZoneById(oldId);
TimeZoneInfo currenttz = TimeZoneInfo.FindSystemTimeZoneById(currentId);

Assert.Equal(oldtz.StandardName, currenttz.StandardName);
Assert.Equal(oldtz.DisplayName, currenttz.DisplayName);
}

[Theory]
[PlatformSpecific(TestPlatforms.Browser)]
[InlineData("America/Buenos_Aires")]
[InlineData("America/Catamarca")]
[InlineData("America/Cordoba")]
[InlineData("America/Jujuy")]
[InlineData("America/Mendoza")]
[InlineData("America/Indianapolis")]
public static void ChangeLocalTimeZone(string id)
{
string originalTZ = Environment.GetEnvironmentVariable("TZ");
try {
TimeZoneInfo.ClearCachedData();
Environment.SetEnvironmentVariable("TZ", id);

TimeZoneInfo localtz = TimeZoneInfo.Local;
TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(id);

Assert.Equal(tz.StandardName, localtz.StandardName);
Assert.Equal(tz.DisplayName, localtz.DisplayName);
}
finally {
TimeZoneInfo.ClearCachedData();
Environment.SetEnvironmentVariable("TZ", originalTZ);
}
}

private static bool IsEnglishUILanguageAndRemoteExecutorSupported => (CultureInfo.CurrentUICulture.Name == "en" || CultureInfo.CurrentUICulture.Name.StartsWith("en-", StringComparison.Ordinal)) && RemoteExecutor.IsSupported;

private static void VerifyConvertException<TException>(DateTimeOffset inputTime, string destinationTimeZoneId) where TException : Exception
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<DownloadTimeZoneData
InputDirectory="$(ArtifactsObjDir)wasm/data/input"
OutputDirectory="$(ArtifactsObjDir)wasm/data/output"
Version="2020a" />
Version="2020d" />
</Target>

<UsingTask TaskName="CreateWasmBundle" AssemblyFile="$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'CreateWasmBundle', 'Debug', '$(NetCoreAppCurrent)', 'publish', 'CreateWasmBundle.dll'))"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DownloadTimeZoneData : Task

private void DownloadTimeZoneDataSource()
{
List<string> files = new List<string>() {"africa", "antarctica", "asia", "australasia", "etcetera", "europe", "northamerica", "southamerica", "zone1970.tab"};
List<string> files = new List<string>() {"africa", "antarctica", "asia", "australasia", "etcetera", "europe", "northamerica", "southamerica", "zone1970.tab", "backward"};
using (var client = new WebClient())
{
Console.WriteLine("Downloading TimeZone data files");
Expand Down

0 comments on commit 9ecbcd7

Please sign in to comment.