diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 186a6bed..9bf3c9e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,12 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + env: DOTNET_NOLOGO: true DOTNET_CLI_TELEMETRY_OPTOUT: 1 diff --git a/Fluid.Tests/Fluid.Tests.csproj b/Fluid.Tests/Fluid.Tests.csproj index a924e0a2..294791f3 100644 --- a/Fluid.Tests/Fluid.Tests.csproj +++ b/Fluid.Tests/Fluid.Tests.csproj @@ -21,6 +21,11 @@ + + diff --git a/Fluid.Tests/MiscFiltersTests.cs b/Fluid.Tests/MiscFiltersTests.cs index 75fcf97b..b5434d9b 100644 --- a/Fluid.Tests/MiscFiltersTests.cs +++ b/Fluid.Tests/MiscFiltersTests.cs @@ -1,6 +1,8 @@ using System; using System.Globalization; using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; using System.Threading.Tasks; using Fluid.Filters; using Fluid.Values; @@ -10,8 +12,26 @@ namespace Fluid.Tests { public class MiscFiltersTests { +#if NET6_0_OR_GREATER + private static readonly TimeZoneInfo Pacific = TimeZoneInfo.FindSystemTimeZoneById("America/Los_Angeles"); + private static readonly TimeZoneInfo Eastern = TimeZoneInfo.FindSystemTimeZoneById("America/New_York"); +#else private static readonly TimeZoneInfo Pacific = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/Los_Angeles"); private static readonly TimeZoneInfo Eastern = TimeZoneConverter.TZConvert.GetTimeZoneInfo("America/New_York"); +#endif + + [Fact] + public void RenderInfo() + { + var result = ""; + + result += $"{RuntimeInformation.OSDescription}\n"; + result += $"{RuntimeInformation.FrameworkDescription}\n"; + result += $".... UseNls: {typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("UseNls", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)} ....\n"; + result += $".... Invariant: {typeof(object).Assembly.GetType("System.Globalization.GlobalizationMode").GetProperty("Invariant", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)} ....\n"; + + throw new ApplicationException(result); + } [Fact] public async Task DefaultReturnsValueIfDefined() diff --git a/Fluid/Filters/MiscFilters.cs b/Fluid/Filters/MiscFilters.cs index 434e15ad..790f7da5 100644 --- a/Fluid/Filters/MiscFilters.cs +++ b/Fluid/Filters/MiscFilters.cs @@ -1,16 +1,14 @@ -using System; +using Fluid.Values; +using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Net; -using System.Text.RegularExpressions; +using System.Reflection; +using System.Text; using System.Text.Json; -using Fluid.Values; -using TimeZoneConverter; +using System.Text.RegularExpressions; using System.Threading.Tasks; -using System.Text; -using System.IO; -using System.Linq; -using System.Reflection; namespace Fluid.Filters { @@ -264,10 +262,27 @@ public static ValueTask ChangeTimeZone(FluidValue input, FilterArgum var timeZone = arguments.At(0).ToStringValue(); - if (!TZConvert.TryGetTimeZoneInfo(timeZone, out var timeZoneInfo)) return new DateTimeValue(value); + +#if NET6_0_OR_GREATER + try + { + var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone); + return new DateTimeValue(TimeZoneInfo.ConvertTime(value, timeZoneInfo)); + } + catch (TimeZoneNotFoundException) + { + return new DateTimeValue(value); + } +#else + if (!TimeZoneConverter.TZConvert.TryGetTimeZoneInfo(timeZone, out var timeZoneInfo)) + { + return new DateTimeValue(value); + } var result = TimeZoneInfo.ConvertTime(value, timeZoneInfo); + return new DateTimeValue(result); +#endif } diff --git a/Fluid/Fluid.csproj b/Fluid/Fluid.csproj index 0013e6c7..e31ed962 100644 --- a/Fluid/Fluid.csproj +++ b/Fluid/Fluid.csproj @@ -6,31 +6,34 @@ latest true true - $(NoWarn);1591 + $(NoWarn);1591 - + + + +