Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Initial perf improvement implementation
  • Loading branch information
mdh1418 authored and github-actions committed Sep 1, 2022
commit 188acf1ece8e489a30147c524cb157e90a81117f
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,47 @@ private static TimeZoneInfo GetLocalTimeZoneCore()
return Utc;
}

private static TimeSpan? _localUtcOffset;
private static object _localUtcOffsetLock = new();
// Shortcut for TimeZoneInfo.Local.GetUtcOffset
internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
{
if (_localUtcOffset != null)
{
CachedData cachedData = s_cachedData;
return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
}

if (_localUtcOffset == null)
{
lock (_localUtcOffsetLock)
{
if (_localUtcOffset == null)
{
Thread loadAndroidTZData = new Thread(() => {
CachedData cachedData = s_cachedData;
_localUtcOffset = cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
});
loadAndroidTZData.IsBackground = true;
loadAndroidTZData.Start();
Thread.Sleep(1000);
}
}
}

object? localDateTimeOffset = AppContext.GetData("LOCAL_DATE_TIME_OFFSET");
int localDateTimeOffsetSeconds;
if (localDateTimeOffset != null)
localDateTimeOffsetSeconds = Convert.ToInt32(localDateTimeOffset);
else
{
throw new Exception ("LOCAL_DATE_TIME_OFFSET NOT SET");
}
long localDateTimeOffsetTicks = localDateTimeOffsetSeconds * 10000000; // 10^7 ticks per second
TimeSpan offset = TimeSpan.FromSeconds(localDateTimeOffsetSeconds);
return offset;
}

private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachineCore(string id, out TimeZoneInfo? value, out Exception? e)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ private static TimeZoneInfo GetLocalTimeZoneCore()
return GetLocalTimeZoneFromTzFile();
}

// Shortcut for TimeZoneInfo.Local.GetUtcOffset
internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
{
CachedData cachedData = s_cachedData;
return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
}

private static TimeZoneInfoResult TryGetTimeZoneFromLocalMachineCore(string id, out TimeZoneInfo? value, out Exception? e)
{
value = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ public OffsetAndRule(int year, TimeSpan offset, AdjustmentRule? rule)
}
}

// Shortcut for TimeZoneInfo.Local.GetUtcOffset
internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
{
CachedData cachedData = s_cachedData;
return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
}

/// <summary>
/// Returns a cloned array of AdjustmentRule objects
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,6 @@ public TimeSpan GetUtcOffset(DateTimeOffset dateTimeOffset) =>
public TimeSpan GetUtcOffset(DateTime dateTime) =>
GetUtcOffset(dateTime, TimeZoneInfoOptions.NoThrowOnInvalidTime, s_cachedData);

// Shortcut for TimeZoneInfo.Local.GetUtcOffset
internal static TimeSpan GetLocalUtcOffset(DateTime dateTime, TimeZoneInfoOptions flags)
{
CachedData cachedData = s_cachedData;
return cachedData.Local.GetUtcOffset(dateTime, flags, cachedData);
}

/// <summary>
/// Returns the Universal Coordinated Time (UTC) Offset for the current TimeZoneInfo instance.
/// </summary>
Expand Down