Add support for Timezones (#2024)
This commit is contained in:
Родитель
d9d2cda535
Коммит
e3ae74171b
|
@ -18,6 +18,8 @@
|
|||
|
||||
<ItemGroup>
|
||||
<WasmItemsToCopy Include="$(MonoIncomingDir)wasm\*" />
|
||||
<WasmItemsToCopy Include="..\TimeZoneData\dotnet.timezones.dat" />
|
||||
|
||||
<BclItemsToCopy Include="$(MonoIncomingDir)bcl\**" />
|
||||
<FrameworkItemsToCopy Include="$(MonoIncomingDir)framework\**" />
|
||||
<BclWipeSpecFiles Include="$(BclWipeSpecDir)**" />
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.WebAssembly.Runtime.TimeZone
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var tzFolder = Path.Combine(Directory.GetCurrentDirectory(), "obj", "data", "output");
|
||||
if (!Directory.Exists(tzFolder))
|
||||
{
|
||||
throw new DirectoryNotFoundException("TZOutput file does not exist. Use run.sh to run this project");
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Tz_database#Area
|
||||
var areas = new[] { "Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia", "Europe", "Indian", "Pacific" };
|
||||
var stream = new MemoryStream();
|
||||
var indices = new List<object[]>();
|
||||
|
||||
foreach (var area in areas)
|
||||
{
|
||||
var directoryInfo = new DirectoryInfo(Path.Combine(tzFolder, area));
|
||||
foreach (var entry in directoryInfo.EnumerateFiles())
|
||||
{
|
||||
System.Console.WriteLine(entry.FullName);
|
||||
var relativePath = entry.FullName.Substring(tzFolder.Length).Trim('/');
|
||||
indices.Add(new object[] { relativePath, entry.Length });
|
||||
|
||||
using (var readStream = entry.OpenRead())
|
||||
readStream.CopyTo(stream);
|
||||
}
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(indices);
|
||||
using (var timezoneFile = File.OpenWrite("dotnet.timezones.dat"))
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
BinaryPrimitives.WriteInt32LittleEndian(bytes, jsonBytes.Length);
|
||||
timezoneFile.Write(bytes);
|
||||
timezoneFile.Write(jsonBytes);
|
||||
|
||||
stream.CopyTo(timezoneFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
## About timezonedata
|
||||
|
||||
This project is used to build the timezone database used by .NET WASM runtime to support timezones. The output of this project is checked in to this folder under the file named `dotnet.timezones.dat`. This output is currently manually regenerated.
|
||||
|
||||
### Building this project
|
||||
|
||||
Prereqs:
|
||||
* *nix machine
|
||||
* .NET Core SDK 3.1 or newer installed.
|
||||
|
||||
Run `run.sh`. This should update the `dotnet.timezones.dat` file. Commit this file to git.
|
|
@ -0,0 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
Двоичный файл не отображается.
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
input_dir="obj/data/input"
|
||||
output_dir="obj/data/output"
|
||||
|
||||
if [[ -d "obj/data" ]]
|
||||
then
|
||||
rm -rf "obj/data"
|
||||
fi
|
||||
|
||||
mkdir -p "$input_dir"
|
||||
mkdir "$output_dir"
|
||||
|
||||
curl -L https://data.iana.org/time-zones/tzdata-latest.tar.gz -o "$input_dir/tzdata.tar.gz"
|
||||
tar xvzf "$input_dir/tzdata.tar.gz" -C "$input_dir"
|
||||
|
||||
files=("africa" "antarctica" "asia" "australasia" "etcetera" "europe" "northamerica" "southamerica")
|
||||
|
||||
for file in "${files[@]}"
|
||||
do
|
||||
zic -d "$output_dir" "$input_dir/$file"
|
||||
done
|
||||
|
||||
dotnet run
|
Загрузка…
Ссылка в новой задаче