Skip to content

Commit 32ba847

Browse files
Merge pull request #146 from ParsePlatform/revert-145-richardross.timezone.fix
Revert "Made TimeZone string generation locale-agnostic for Windows Phone and Unity."
2 parents 4fc5be3 + b3a7bc7 commit 32ba847

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

Parse/Internal/PlatformHooks/Phone/PlatformHooks.Phone.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,17 @@ public string DeviceType {
150150

151151
public string DeviceTimeZone {
152152
get {
153-
TimeSpan utcOffset = TimeZoneInfo.Local.BaseUtcOffset;
154-
return String.Format("GMT{0}{1}:{2:d2}",
155-
offset.TotalSeconds < 0 ? "-" : "+",
156-
Math.Abs(offset.Hours),
157-
Math.Abs(offset.Minutes)
158-
);
153+
// We need the system string to be in english so we'll have the proper key in our lookup table.
154+
var culture = Thread.CurrentThread.CurrentCulture;
155+
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
156+
string windowsName = TimeZoneInfo.Local.StandardName;
157+
Thread.CurrentThread.CurrentCulture = culture;
158+
159+
if (ParseInstallation.TimeZoneNameMap.ContainsKey(windowsName)) {
160+
return ParseInstallation.TimeZoneNameMap[windowsName];
161+
} else {
162+
return null;
163+
}
159164
}
160165
}
161166

Parse/Internal/PlatformHooks/Unity/PlatformHooks.Unity.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,16 @@ public string DeviceType {
8787

8888
public string DeviceTimeZone {
8989
get {
90-
TimeSpan utcOffset = TimeZoneInfo.Local.BaseUtcOffset;
91-
return String.Format("GMT{0}{1}:{2:d2}",
92-
offset.TotalSeconds < 0 ? "-" : "+",
93-
Math.Abs(offset.Hours),
94-
Math.Abs(offset.Minutes)
95-
);
90+
try {
91+
string windowsName = TimeZoneInfo.Local.StandardName;
92+
if (ParseInstallation.TimeZoneNameMap.ContainsKey(windowsName)) {
93+
return ParseInstallation.TimeZoneNameMap[windowsName];
94+
} else {
95+
return null;
96+
}
97+
} catch (TimeZoneNotFoundException) {
98+
return null;
99+
}
96100
}
97101
}
98102

0 commit comments

Comments
 (0)