Skip to content

Commit bbba380

Browse files
Made TimeZone string generation locale-agnostic for Windows Phone and Unity.
Previously, TimeZone string generation that we sent along with ParseInstallation was dependent upon the `CurrentCulture` of the device being set to the english locale (as `StandardName` is localized, WHAT?!) Our new, fancy TimeZone string is now generated agnostically of the current device locale. There is potential for information about the specific region of the time zone to be lost here, but most applications should not require this. This should fix #138.
1 parent a60db2e commit bbba380

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

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

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

151151
public string DeviceTimeZone {
152152
get {
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-
}
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.Seconds)
158+
);
164159
}
165160
}
166161

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

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

8888
public string DeviceTimeZone {
8989
get {
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-
}
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.Seconds)
95+
);
10096
}
10197
}
10298

0 commit comments

Comments
 (0)