From ab4946a1b8b2adc41773559db4f060c7a211900c Mon Sep 17 00:00:00 2001 From: Bruno Abrantes Date: Wed, 20 Aug 2014 11:58:06 +0100 Subject: [PATCH 1/2] Parses date strings using a standard timezone --- Classes/Categories/NSDate+StringParsing.m | 2 +- Example/CJKitTests/CJCommentTests.m | 2 +- Example/CJKitTests/CJEventTests.m | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Classes/Categories/NSDate+StringParsing.m b/Classes/Categories/NSDate+StringParsing.m index cdce990..a767980 100644 --- a/Classes/Categories/NSDate+StringParsing.m +++ b/Classes/Categories/NSDate+StringParsing.m @@ -36,7 +36,7 @@ + (NSDate *)dateFromString:(NSString *)dateString NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setLocale:locale]; - [dateFormatter setTimeZone:[NSTimeZone systemTimeZone]]; + [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]]; NSDate *date = [dateFormatter dateFromString:dateString]; return date; diff --git a/Example/CJKitTests/CJCommentTests.m b/Example/CJKitTests/CJCommentTests.m index 8a4cf9e..3fe7d9d 100644 --- a/Example/CJKitTests/CJCommentTests.m +++ b/Example/CJKitTests/CJCommentTests.m @@ -95,7 +95,7 @@ [[theValue(components.day) should] equal:theValue(24)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(15)]; + [[theValue(components.hour) should] equal:theValue(16)]; [[theValue(components.minute) should] equal:theValue(31)]; [[theValue(components.second) should] equal:theValue(5)]; }); diff --git a/Example/CJKitTests/CJEventTests.m b/Example/CJKitTests/CJEventTests.m index 042678d..fc1bfc0 100644 --- a/Example/CJKitTests/CJEventTests.m +++ b/Example/CJKitTests/CJEventTests.m @@ -119,7 +119,7 @@ - (BOOL)isRetinaDisplay; [[theValue(components.day) should] equal:theValue(21)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(18)]; + [[theValue(components.hour) should] equal:theValue(19)]; [[theValue(components.minute) should] equal:theValue(0)]; [[theValue(components.second) should] equal:theValue(0)]; }); @@ -132,7 +132,7 @@ - (BOOL)isRetinaDisplay; [[theValue(components.day) should] equal:theValue(21)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(20)]; + [[theValue(components.hour) should] equal:theValue(21)]; [[theValue(components.minute) should] equal:theValue(59)]; [[theValue(components.second) should] equal:theValue(0)]; }); @@ -145,7 +145,7 @@ - (BOOL)isRetinaDisplay; [[theValue(components.day) should] equal:theValue(22)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(16)]; + [[theValue(components.hour) should] equal:theValue(17)]; [[theValue(components.minute) should] equal:theValue(14)]; [[theValue(components.second) should] equal:theValue(34)]; }); @@ -158,7 +158,7 @@ - (BOOL)isRetinaDisplay; [[theValue(components.day) should] equal:theValue(28)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(18)]; + [[theValue(components.hour) should] equal:theValue(19)]; [[theValue(components.minute) should] equal:theValue(0)]; [[theValue(components.second) should] equal:theValue(0)]; }); From 91bd3ef05905007c928820ae2a1a1012bcc1ecb5 Mon Sep 17 00:00:00 2001 From: Bruno Abrantes Date: Wed, 20 Aug 2014 05:28:24 -0600 Subject: [PATCH 2/2] Uses a GMT calendar when running specs --- Example/CJKitTests/CJCommentTests.m | 7 +++++-- Example/CJKitTests/CJEventTests.m | 19 +++++++++++-------- Example/CJKitTests/CJUserTests.m | 7 +++++-- Example/CJKitTests/CJVenueTests.m | 5 ++++- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Example/CJKitTests/CJCommentTests.m b/Example/CJKitTests/CJCommentTests.m index 3fe7d9d..d9d9830 100644 --- a/Example/CJKitTests/CJCommentTests.m +++ b/Example/CJKitTests/CJCommentTests.m @@ -13,6 +13,9 @@ SPEC_BEGIN(CJCOMMENTSPEC) describe(@"Comment Model", ^{ + NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + NSDictionary *stub = @{ @"id": @"dab8df0390b14949", @"message": @"This is awesome", @@ -90,12 +93,12 @@ describe(@"#createdAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:comment.createdAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:comment.createdAt]; [[theValue(components.day) should] equal:theValue(24)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(16)]; + [[theValue(components.hour) should] equal:theValue(15)]; [[theValue(components.minute) should] equal:theValue(31)]; [[theValue(components.second) should] equal:theValue(5)]; }); diff --git a/Example/CJKitTests/CJEventTests.m b/Example/CJKitTests/CJEventTests.m index fc1bfc0..b776b08 100644 --- a/Example/CJKitTests/CJEventTests.m +++ b/Example/CJKitTests/CJEventTests.m @@ -24,6 +24,9 @@ - (BOOL)isRetinaDisplay; SPEC_BEGIN(CJEVENTSPEC) describe(@"Event Model", ^{ + NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + NSDictionary *stub = @{ @"id": @55, @"followersCount": @10, @@ -114,12 +117,12 @@ - (BOOL)isRetinaDisplay; describe(@"#startsAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.startsAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.startsAt]; [[theValue(components.day) should] equal:theValue(21)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(19)]; + [[theValue(components.hour) should] equal:theValue(18)]; [[theValue(components.minute) should] equal:theValue(0)]; [[theValue(components.second) should] equal:theValue(0)]; }); @@ -127,12 +130,12 @@ - (BOOL)isRetinaDisplay; describe(@"#endsAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.endsAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.endsAt]; [[theValue(components.day) should] equal:theValue(21)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(21)]; + [[theValue(components.hour) should] equal:theValue(20)]; [[theValue(components.minute) should] equal:theValue(59)]; [[theValue(components.second) should] equal:theValue(0)]; }); @@ -140,12 +143,12 @@ - (BOOL)isRetinaDisplay; describe(@"#updatedAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.updatedAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.updatedAt]; [[theValue(components.day) should] equal:theValue(22)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(17)]; + [[theValue(components.hour) should] equal:theValue(16)]; [[theValue(components.minute) should] equal:theValue(14)]; [[theValue(components.second) should] equal:theValue(34)]; }); @@ -153,12 +156,12 @@ - (BOOL)isRetinaDisplay; describe(@"#reviewEndsAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.reviewEndsAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:event.reviewEndsAt]; [[theValue(components.day) should] equal:theValue(28)]; [[theValue(components.month) should] equal:theValue(4)]; [[theValue(components.year) should] equal:theValue(2014)]; - [[theValue(components.hour) should] equal:theValue(19)]; + [[theValue(components.hour) should] equal:theValue(18)]; [[theValue(components.minute) should] equal:theValue(0)]; [[theValue(components.second) should] equal:theValue(0)]; }); diff --git a/Example/CJKitTests/CJUserTests.m b/Example/CJKitTests/CJUserTests.m index f57ad73..a13125b 100644 --- a/Example/CJKitTests/CJUserTests.m +++ b/Example/CJKitTests/CJUserTests.m @@ -12,6 +12,9 @@ SPEC_BEGIN(CJUSERSPEC) describe(@"User Model", ^{ + NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + NSDictionary *stub = @{ @"id": @443, @"email": @"bruno.abrantes@clubjudge.com", @@ -116,7 +119,7 @@ describe(@"#createdAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:user.createdAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:user.createdAt]; [[theValue(components.day) should] equal:theValue(19)]; [[theValue(components.month) should] equal:theValue(03)]; @@ -189,7 +192,7 @@ describe(@"#birthdate", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:user.birthdate]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:user.birthdate]; [[theValue(components.day) should] equal:theValue(13)]; [[theValue(components.month) should] equal:theValue(10)]; diff --git a/Example/CJKitTests/CJVenueTests.m b/Example/CJKitTests/CJVenueTests.m index 481ce1b..73d8b75 100644 --- a/Example/CJKitTests/CJVenueTests.m +++ b/Example/CJKitTests/CJVenueTests.m @@ -23,6 +23,9 @@ - (BOOL)isRetinaDisplay; SPEC_BEGIN(CJVENUESPEC) describe(@"Venue Model", ^{ + NSCalendar* calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + [calendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]]; + NSDictionary *stub = @{ @"address": @{ @"city": @{ @@ -222,7 +225,7 @@ - (BOOL)isRetinaDisplay; describe(@"#updatedAt", ^{ it(@"produces a correct mapping", ^{ - NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:venue.updatedAt]; + NSDateComponents *components = [calendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitTimeZone fromDate:venue.updatedAt]; [[theValue(components.day) should] equal:theValue(17)]; [[theValue(components.month) should] equal:theValue(12)];