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

Bug/system.time zone not found exception on raspberry pi #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# Jetbrains rider idea files
.idea/
1 change: 1 addition & 0 deletions DSMRParser/DSMRParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NodaTime" Version="3.1.11" />
</ItemGroup>

</Project>
10 changes: 8 additions & 2 deletions DSMRParser/Models/Telegram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Globalization;
using System.Linq;
using System.Text;
using NodaTime;
using NodaTime.Text;

namespace DSMRParser.Models;

Expand All @@ -26,7 +28,7 @@ public class Telegram(string? identification, IEnumerable<(OBISId obisid, IEnume
{
/// <summary>The culture used for parsing values (affecting parsing of values like "1.234,56" vs "1,234.56".</summary>
private static readonly CultureInfo _culture = CultureInfo.InvariantCulture;
private static readonly TimeZoneInfo _dutchtimezone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
private static readonly DateTimeZone _dutchtimezone = DateTimeZoneProviders.Tzdb["Europe/Amsterdam"];

/// <summary>An empty dictionary of OBIS values.</summary>
protected static readonly IReadOnlyDictionary<OBISId, IEnumerable<string?>> EMPTY = new ReadOnlyDictionary<OBISId, IEnumerable<string?>>(Array.Empty<OBISDescriptor>().ToDictionary(i => i.Id, i => Enumerable.Empty<string?>()));
Expand Down Expand Up @@ -197,9 +199,13 @@ protected static bool TryParseDateTimeOffsetCore(string? value, out DateTimeOffs
{
if (DateTime.TryParseExact(value?.TrimEnd('W', 'S'), "yyMMddHHmmss", _culture, DateTimeStyles.None, out var dt))
{
result = new DateTimeOffset(dt, _dutchtimezone.GetUtcOffset(dt));
var localDt = LocalDateTime.FromDateTime(dt);
var zonedDt = localDt.InZoneLeniently(_dutchtimezone);
result = zonedDt.ToDateTimeOffset();

return true;
}

result = default;
return false;
}
Expand Down