Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'feature/513-dates-before-1970'

  • Loading branch information...
commit d0b859484e6243eb607ef9987d9d9f9bf9d94043 2 parents 55c72a5 + 377d350
@blakewatters blakewatters authored
View
3  Code/Support/RKDotNetDateFormatter.h
@@ -42,8 +42,9 @@
Acceptable examples are:
/Date(1112715000000-0500)/
/Date(1112715000000)/
+ /Date(-1112715000000)/
Where 1112715000000 is the number of milliseconds since January 1, 1970 00:00 GMT/UTC, and -0500 represents the
- timezone offset from GMT in 24-hour time.
+ timezone offset from GMT in 24-hour time. Negatives milliseconds are treated as dates before January 1, 1970.
*NOTE* NSDate objects do not have timezones, and you should never change an actual date value based on a
timezone offset. However, timezones are important when presenting dates to the user. Therefore,
View
2  Code/Support/RKDotNetDateFormatter.m
@@ -58,7 +58,7 @@ - (id)init {
self.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
self.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
[self setDateFormat:@"ZZ"]; // GMT offset, like "-0500"
- NSString *pattern = @"\\/Date\\((\\d+)((?:[\\+\\-]\\d+)?)\\)\\/"; // /Date(mSecs)/ or /Date(mSecs-0400)/
+ NSString *pattern = @"\\/Date\\((-?\\d+)((?:[\\+\\-]\\d+)?)\\)\\/"; // /Date(mSecs)/ or /Date(-mSecs)/ or /Date(mSecs-0400)/
dotNetExpression = [[NSRegularExpression alloc] initWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:NULL];
}
return self;
View
14 Specs/Support/RKDotNetDateFormatterSpec.m
@@ -44,6 +44,13 @@ - (void)testShouldCreateADateFromDotNetWithoutAnOffset {
assertThat([date description], is(equalTo(@"2005-04-05 15:30:00 +0000")));
}
+- (void)testShouldCreateADateFromDotNetBefore1970WithoutAnOffset {
+ NSString *dotNetString = @"/Date(-864000000000)/";
+ RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
+ NSDate *date = [formatter dateFromString:dotNetString];
+ assertThat([date description], is(equalTo(@"1942-08-16 00:00:00 +0000")));
+}
+
- (void)testShouldFailToCreateADateFromInvalidStrings {
RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
NSDate *date = [formatter dateFromString:nil];
@@ -63,5 +70,12 @@ - (void)testShouldCreateADotNetStringFromADateWithATimeZone {
assertThat(string, is(equalTo(@"/Date(1000212360000-0400)/")));
}
+- (void)testShouldCreateADotNetStringFromADateBefore1970WithoutAnOffset {
+ RKDotNetDateFormatter *formatter = [RKDotNetDateFormatter dotNetDateFormatter];
+ NSDate *referenceDate = [NSDate dateWithTimeIntervalSince1970:-1000212360];
+ NSString *string = [formatter stringFromDate:referenceDate];
+ assertThat(string, is(equalTo(@"/Date(-1000212360000+0000)/")));
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.