Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TimeZoneConverter dependency on net6.0 #398

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Fluid.Tests/Fluid.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<LangVersion>9</LangVersion>
<DefineConstants Condition="'$(Compiled)' == 'true'">$(DefineConstants);COMPILED</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0'">$(DefineConstants);HAS_TIMEZONE_API</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions Fluid.Tests/MiscFiltersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ namespace Fluid.Tests
{
public class MiscFiltersTests
{
#if HAS_TIMEZONE_API
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 async Task DefaultReturnsValueIfDefined()
Expand Down
36 changes: 27 additions & 9 deletions Fluid/Filters/MiscFilters.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
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;
#if !HAS_TIMEZONE_API
using TimeZoneConverter;
#endif

namespace Fluid.Filters
{
Expand Down Expand Up @@ -264,10 +265,27 @@ public static ValueTask<FluidValue> ChangeTimeZone(FluidValue input, FilterArgum

var timeZone = arguments.At(0).ToStringValue();

if (!TZConvert.TryGetTimeZoneInfo(timeZone, out var timeZoneInfo)) return new DateTimeValue(value);

#if HAS_TIMEZONE_API
sebastienros marked this conversation as resolved.
Show resolved Hide resolved
try
{
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone);
return new DateTimeValue(TimeZoneInfo.ConvertTime(value, timeZoneInfo));
}
catch (TimeZoneNotFoundException)
{
return new DateTimeValue(value);
}
#else
if (!TZConvert.TryGetTimeZoneInfo(timeZone, out var timeZoneInfo))
{
return new DateTimeValue(value);
}

var result = TimeZoneInfo.ConvertTime(value, timeZoneInfo);

return new DateTimeValue(result);
#endif
}


Expand Down
8 changes: 6 additions & 2 deletions Fluid/Fluid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@
<LangVersion>latest</LangVersion>
<IsPackable>true</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<NoWarn>$(NoWarn);1591</NoWarn>
<DefineConstants Condition="'$(TargetFramework)'=='net6.0'">$(DefineConstants);HAS_TIMEZONE_API</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Parlot" Version="0.0.17" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="1.1.1" />
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
<PackageReference Include="System.Text.Json" Version="5.0.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.1'">
<PackageReference Include="System.Text.Json" Version="5.0.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
</ItemGroup>

<!-- Keep specific targets for netcoreapp3.1 and net5.0 since it removes some dependencies -->
<ItemGroup Condition="'$(TargetFramework)'=='netcoreapp3.1'">
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net5.0'">
<PackageReference Include="TimeZoneConverter" Version="3.5.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net6.0'">
Expand Down