Skip to content

Commit 167fffc

Browse files
committed
Use the system's TimeZoneInfo.Utc cache.
This should be safer if someone calls ClearCachedData.
1 parent e0a73c8 commit 167fffc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/NetTopologySuite.IO.GPX/GpxReaderSettings.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ namespace NetTopologySuite.IO
88
/// </summary>
99
public sealed class GpxReaderSettings
1010
{
11-
private static readonly TimeZoneInfo UtcTimeZone = TimeZoneInfo.Utc;
12-
1311
private static readonly GpxExtensionReader DefaultExtensionReader = new GpxExtensionReader();
1412

13+
private TimeZoneInfo timeZoneInfo;
14+
1515
/// <summary>
1616
/// Gets or sets the <see cref="System.TimeZoneInfo"/> instance that the system should use
1717
/// to interpret timestamps in the GPX file, when the file itself does not contain time zone
1818
/// information. Default is <see cref="TimeZoneInfo.Utc"/>.
19+
/// <para>
20+
/// <see langword="null"/> is treated as <see cref="TimeZoneInfo.Utc"/>, but please prefer
21+
/// <see langword="null"/> so that <see cref="TimeZoneInfo.ClearCachedData"/> does not
22+
/// affect our correctness.
23+
/// </para>
1924
/// </summary>
20-
public TimeZoneInfo TimeZoneInfo { get; set; } = UtcTimeZone;
25+
public TimeZoneInfo TimeZoneInfo
26+
{
27+
get => this.timeZoneInfo ?? TimeZoneInfo.Utc;
28+
set => this.timeZoneInfo = value;
29+
}
2130

2231
/// <summary>
2332
/// Gets or sets the <see cref="GpxExtensionReader"/> instance to use to convert GPX

src/NetTopologySuite.IO.GPX/GpxWriterSettings.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,26 @@ namespace NetTopologySuite.IO
88
/// </summary>
99
public sealed class GpxWriterSettings
1010
{
11-
private static readonly TimeZoneInfo UtcTimeZone = TimeZoneInfo.Utc;
12-
1311
private static readonly GpxExtensionWriter DefaultExtensionWriter = new GpxExtensionWriter();
1412

13+
private TimeZoneInfo timeZoneInfo;
14+
1515
/// <summary>
1616
/// Gets or sets the <see cref="System.TimeZoneInfo"/> instance that the system should use
1717
/// to produce timestamps for the GPX file. Default is <see cref="TimeZoneInfo.Utc"/>.
1818
/// When overwriting this property, note that the XSD schema specifies that, by convention,
1919
/// timestamps in GPX files are expected to be in UTC.
20+
/// <para>
21+
/// <see langword="null"/> is treated as <see cref="TimeZoneInfo.Utc"/>, but please prefer
22+
/// <see langword="null"/> so that <see cref="TimeZoneInfo.ClearCachedData"/> does not
23+
/// affect our correctness.
24+
/// </para>
2025
/// </summary>
21-
public TimeZoneInfo TimeZoneInfo { get; set; } = UtcTimeZone;
26+
public TimeZoneInfo TimeZoneInfo
27+
{
28+
get => this.timeZoneInfo ?? TimeZoneInfo.Utc;
29+
set => this.timeZoneInfo = value;
30+
}
2231

2332
/// <summary>
2433
/// Gets or sets the <see cref="GpxExtensionWriter"/> instance to use to convert

0 commit comments

Comments
 (0)