Fixed: Timezone abbreviation was not working with the latest changes on all setups.

This is still not 100% but looks like it works a little bit better
This commit is contained in:
Martin Carlberg committed 2021-09-21 15:38:51 +02:00
1 parent 4deb7a3f51
commit 9e6f1e0dc3
2 files changed
+6 -12

No files matched your search

+5 -6
View File
@@ -46,12 +46,11 @@ var abbreviationDictionary,
function abbreviationForDate(date)
{
var abbreviation = String(String(date).split("(")[1]).split(")")[0];
if (abbreviation.includes(" "))
// Some browsers will now have the time zone in long format. Take first letter of each word.
// This is not 100% but is better than nothing.
abbreviation = abbreviation.split(" ").map(function(l) { return l[0]}).join("");
// Sometimes the browsers will give unmatched timezones in other languages so try one more thing
// Take the locale string for english in the US. It has the following format (9/21/2021, 2:40:44 PM Central European Summer Time)
// Remove the date and time with this regex and take first letter in each word in the time zone name.
// This is not 100% but is better than nothing as JAvascript has no good support for this.
var abbreviation = date.toLocaleString('en-US', {timeZoneName : 'long'}).replace(/^([0]?\d|[1][0-2])\/((?:[0]?|[1-2])\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(,?\s*([0]?\d|[1][0-2])(\:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})?\s*/, "").split(" ").map(function(l) { return l[0]}).join("");
return abbreviation;
}
+1 -6
View File
@@ -261,12 +261,7 @@
{
var timeZone = [CPTimeZone localTimeZone],
abbreviation = [timeZone abbreviationForDate:_date],
expected = String(String(_date).split("(")[1]).split(")")[0];
if (expected.includes(" "))
// Some browsers will now have the time zone in long format. Take first letter of each word.
// This is not 100% but is better than nothing.
expected = expected.split(" ").map(function(l) { return l[0]}).join("");
expected = _date.toLocaleString('en-US', {timeZoneName : 'long'}).replace(/^([0]?\d|[1][0-2])\/((?:[0]?|[1-2])\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(,?\s*([0]?\d|[1][0-2])(\:[0-5]\d){1,2})*\s*([aApP][mM]{0,2})?\s*/, "").split(" ").map(function(l) { return l[0]}).join("");
[self assert:abbreviation equals:expected];
}