mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
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:
@@ -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],
|
||||
|
||||
@@ -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"];
|
||||
|
||||
Reference in New Issue
Block a user