Skip to content

Commit 4fc5be3

Browse files
Merge pull request #145 from ParsePlatform/richardross.timezone.fix
Made TimeZone string generation locale-agnostic for Windows Phone and Unity.
2 parents a60db2e + e076b09 commit 4fc5be3

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.Minutes)
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.Minutes)
95+
);
10096
}
10197
}
10298

0 commit comments

Comments
 (0)