mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Fixed: Abbreviation for a timezone is not handled in JavaScript. This changes makes it better but not perfect.
This commit is contained in:
+17
-6
@@ -44,6 +44,17 @@ var abbreviationDictionary,
|
||||
timeZoneDataVersion,
|
||||
localizedName;
|
||||
|
||||
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("");
|
||||
|
||||
return abbreviation;
|
||||
}
|
||||
/*!
|
||||
@class CPTimeZone
|
||||
@ingroup foundation
|
||||
@@ -269,11 +280,11 @@ var abbreviationDictionary,
|
||||
};
|
||||
|
||||
var date = [CPDate date],
|
||||
abbreviation = String(String(date).split("(")[1]).split(")")[0];
|
||||
abbreviation = abbreviationForDate(date);
|
||||
|
||||
localTimeZone = [self timeZoneWithAbbreviation:abbreviation];
|
||||
systemTimeZone = [self timeZoneWithAbbreviation:abbreviation];
|
||||
defaultTimeZone = [self timeZoneWithAbbreviation:abbreviation];
|
||||
systemTimeZone = localTimeZone;
|
||||
defaultTimeZone = localTimeZone;
|
||||
|
||||
localizedName = @{
|
||||
@"en" : englishLocalizedName,
|
||||
@@ -430,7 +441,7 @@ var abbreviationDictionary,
|
||||
+ (void)resetSystemTimeZone
|
||||
{
|
||||
var date = [CPDate date],
|
||||
abbreviation = String(String(date).split("(")[1]).split(")")[0];
|
||||
abbreviation = abbreviationForDate(date);
|
||||
|
||||
systemTimeZone = [self timeZoneWithAbbreviation:abbreviation];
|
||||
|
||||
@@ -560,7 +571,7 @@ var abbreviationDictionary,
|
||||
if (!date)
|
||||
return nil;
|
||||
|
||||
return String(String(date).split("(")[1]).split(")")[0];
|
||||
return abbreviationForDate(date);
|
||||
}
|
||||
|
||||
/*! Returns the number of seconds from GMT for the given date
|
||||
@@ -573,7 +584,7 @@ var abbreviationDictionary,
|
||||
if (!date)
|
||||
return nil;
|
||||
|
||||
var abbreviation = String(String(date).split("(")[1]).split(")")[0];
|
||||
var abbreviation = abbreviationForDate(date);
|
||||
|
||||
return [timeDifferenceFromUTC valueForKey:abbreviation] * 60;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeZone = [CPTimeZone timeZoneWithName:nil];
|
||||
[CPTimeZone timeZoneWithName:nil];
|
||||
[self fail:"Invalid value provided for tzName"];
|
||||
}
|
||||
catch (e)
|
||||
@@ -140,7 +140,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeZone = [CPTimeZone timeZoneWithName:nil data:_data];
|
||||
[CPTimeZone timeZoneWithName:nil data:_data];
|
||||
[self fail:"Invalid value provided for tzName"];
|
||||
}
|
||||
catch (e)
|
||||
@@ -204,7 +204,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeZone = [[CPTimeZone alloc] initWithName:nil];
|
||||
[[CPTimeZone alloc] initWithName:nil];
|
||||
[self fail:"Invalid value provided for tzName"];
|
||||
}
|
||||
catch (e)
|
||||
@@ -248,7 +248,7 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
var timeZone = [[CPTimeZone alloc] initWithName:nil data:_data];
|
||||
[[CPTimeZone alloc] initWithName:nil data:_data];
|
||||
[self fail:"Invalid value provided for tzName"];
|
||||
}
|
||||
catch (e)
|
||||
@@ -260,9 +260,15 @@
|
||||
- (void)testAbbreviationWithDate
|
||||
{
|
||||
var timeZone = [CPTimeZone localTimeZone],
|
||||
abbreviation = [timeZone abbreviationForDate:_date];
|
||||
abbreviation = [timeZone abbreviationForDate:_date],
|
||||
expected = String(String(_date).split("(")[1]).split(")")[0];
|
||||
|
||||
[self assert:abbreviation equals: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("");
|
||||
|
||||
[self assert:abbreviation equals:expected];
|
||||
}
|
||||
|
||||
- (void)testAbbreviationWithNilDate
|
||||
|
||||
Reference in New Issue
Block a user