Skip to content

Commit

Permalink
Test date directly
Browse files Browse the repository at this point in the history
  • Loading branch information
lmeier committed Jan 21, 2025
1 parent b28bada commit 9b5b993
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,20 @@ - (void)test_Radar_reverseGeocodeLocation_success {
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)-18000);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
NSDateComponents *nycComponents = [[NSDateComponents alloc] init];
nycComponents.year = 2025;
nycComponents.month = 1; // January
nycComponents.day = 21;
nycComponents.hour = 17;
nycComponents.minute = 19;
nycComponents.second = 23;
NSDate *expectedNYCDate = [calendar dateFromComponents:nycComponents];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedNYCDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"-05:00"], @"NYC time should end with -05:00 but was: %@", currentTime);

[expectation fulfill];
Expand Down Expand Up @@ -1354,8 +1366,22 @@ - (void)test_Radar_reverseGeocode_london_timezone {
XCTAssertEqualObjects(address.timeZone.code, @"GMT");
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)0);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);

XCTAssertNotNil(address.timeZone.currentTime);

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];

NSDateComponents *components = [[NSDateComponents alloc] init];
components.year = 2025;
components.month = 1;
components.day = 21;
components.hour = 17;
components.minute = 22;
components.second = 19;

NSDate *expectedLondonDate = [calendar dateFromComponents:components];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedLondonDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"Z"], @"London time should end with Z but was: %@", currentTime);
Expand Down Expand Up @@ -1385,6 +1411,18 @@ - (void)test_Radar_reverseGeocode_darwin_timezone {
XCTAssertEqual(address.timeZone.utcOffset, (NSInteger)34200);
XCTAssertEqual(address.timeZone.dstOffset, (NSInteger)0);

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
calendar.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
NSDateComponents *darwinComponents = [[NSDateComponents alloc] init];
darwinComponents.year = 2025;
darwinComponents.month = 1;
darwinComponents.day = 21;
darwinComponents.hour = 18;
darwinComponents.minute = 47;
darwinComponents.second = 35;
NSDate *expectedDarwinDate = [calendar dateFromComponents:darwinComponents];
XCTAssertEqualObjects(address.timeZone.currentTime, expectedDarwinDate);

NSDictionary *timezoneDict = [address.timeZone dictionaryValue];
NSString *currentTime = timezoneDict[@"currentTime"];
XCTAssertTrue([currentTime hasSuffix:@"+09:30"], @"Darwin time should end with +09:30 but was: %@", currentTime);
Expand Down

0 comments on commit 9b5b993

Please sign in to comment.