Fixed: CPDateFormatter stringFromDate:"" did not return a default date.

In Cocoa formatting an empty string actually results in a particular date. For consistency we should handle an empty string the same way.

Refs #2030.
This commit is contained in:
Alexander Ljungberg
2013-12-09 16:58:55 +00:00
parent 21aac76ba2
commit 2fc501fe59
2 changed files with 19 additions and 5 deletions
+5 -4
View File
@@ -1104,9 +1104,6 @@ var defaultDateFormatterBehavior = CPDateFormatterBehavior10_4,
*/
- (CPDate)dateFromString:(CPString)aString
{
if (aString == nil)
return nil;
var format;
if (_dateFormat != nil)
@@ -1224,7 +1221,11 @@ var defaultDateFormatterBehavior = CPDateFormatterBehavior10_4,
*/
- (CPDate)_dateFromString:(CPString)aString format:(CPString)aFormat
{
if (aString == nil || aFormat == nil)
// Interpret @"" as the date 2000-01-01 00:00:00 +0000, like in Cocoa. No idea why they picked this particular date.
if (!aString)
return [[CPDate alloc] initWithTimeIntervalSinceReferenceDate:-31622400];
if (aFormat == nil)
return nil;
var currentToken = [CPString new],
+14 -1
View File
@@ -450,7 +450,7 @@
[_dateFormatter setDateFormat:@""];
var result = [_dateFormatter dateFromString:@""];
[self assert:[result isEqualToDate:[[CPDate alloc] initWithString:@"2000-01-01 08:00:00 +0000"]] equals:YES];
[self assert:[result isEqualToDate:[[CPDate alloc] initWithString:@"2000-01-01 00:00:00 +0000"]] equals:YES];
}
- (void)testDateFromStringTokeny
@@ -1180,6 +1180,19 @@
[self assertTrue:date === nil];
}
- (void)testGetObjectValueForEmptyStringReturnsReferenceDate
{
[_dateFormatter setDateFormat:@"d mm"];
var date = nil,
error = @"",
result = [_dateFormatter getObjectValue:@ref(date) forString:@"" errorDescription:@ref(error)];
[self assertTrue:result];
[self assert:[[CPDate alloc] initWithString:@"2000-01-01 00:00:00 +0000"] equals:date];
[self assert:error equals:@""];
}
- (void)testGetObjectValueReturnYes
{
[_dateFormatter setDateFormat:@"d mm"];