Display offset in TimeZoneInfo.DisplayName (#20728)
authorEgor Bogatov <egorbo@gmail.com>
Thu, 1 Nov 2018 21:13:10 +0000 (00:13 +0300)
committerTarek Mahmoud Sayed <tarekms@microsoft.com>
Thu, 1 Nov 2018 21:13:10 +0000 (14:13 -0700)
* Display offset in TimeZoneInfo.DisplayInfo

* Display offset in TimeZoneInfo.DisplayInfo

* prefer +00.00

* Update TimeZoneInfo.Unix.cs

src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs

index 5645c2a..ebeb301 100644 (file)
@@ -80,6 +80,14 @@ namespace System
             GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType.Standard, ref _standardDisplayName);
             GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType.DaylightSavings, ref _daylightDisplayName);
 
+            if (_standardDisplayName == _displayName)
+            {
+                if (_baseUtcOffset >= TimeSpan.Zero)
+                    _displayName = $"(UTC+{_baseUtcOffset:hh\\:mm}) {_standardDisplayName}";
+                else
+                    _displayName = $"(UTC-{_baseUtcOffset:hh\\:mm}) {_standardDisplayName}";
+            }
+
             // TZif supports seconds-level granularity with offsets but TimeZoneInfo only supports minutes since it aligns
             // with DateTimeOffset, SQL Server, and the W3C XML Specification
             if (_baseUtcOffset.Ticks % TimeSpan.TicksPerMinute != 0)