Skip to content

Commit

Permalink
[ios-sdk] Update NSDate serialization to support new "Events Timezone…
Browse files Browse the repository at this point in the history
…" platform migration.

Summary:
{VFU} The "Events Timezone" platform migration changes the date/time formats accepted and returned
by the Graph API. We can no longer serialize them as Unix timestamps, and must put them in ISO-8601
format instead. Older apps that are not in this migration can work around this change by explicitly
serializing dates as timestamps themselves, and sending them as strings.

Test Plan:
- Migrated unit test app into "Events Timezone" migration
- Ran unit tests

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: mmarucheck

CC: msdkexp@, platform-diffs@lists

Differential Revision: https://phabricator.fb.com/D543336
  • Loading branch information
Chris Lang committed Aug 13, 2012
1 parent b67cae9 commit 77984b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
11 changes: 9 additions & 2 deletions src/FBRequestConnection.m
Expand Up @@ -865,8 +865,15 @@ + (void)processGraphObjectPropertyKey:(NSString*)key
// Just serialize these.
action(key, value);
} else if ([value isKindOfClass:[NSDate class]]) {
// We have two options for serializing dates. This is the easy one.
value = [NSString stringWithFormat:@"%.0f", [value timeIntervalSince1970]];
// The "Events Timezone" platform migration affects what date/time formats Facebook accepts and returns.
// Apps created after 8/1/12 (or apps that have explicitly enabled the migration) should send/receive
// dates in ISO-8601 format. Pre-migration apps can send as Unix timestamps. Since the future is ISO-8601,
// that is what we support here. Apps that need pre-migration behavior can explicitly send these as
// integer timestamps rather than NSDates.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];

value = [dateFormatter stringFromDate:value];
action(key, value);
} else if ([value isKindOfClass:[NSArray class]]) {
// Arrays are serialized as multiple elements with keys of the
Expand Down
9 changes: 4 additions & 5 deletions src/tests/FBGraphObjectTests.m
Expand Up @@ -298,14 +298,14 @@ - (void)testCommentRoundTrip
[comment setObject:commentMessage forKey:@"message"];

id comment1 = [self postComment:comment toStatusID:statusID];
NSString *comment1ID = [[[comment1 objectForKey:@"id"] retain] autorelease];
NSString *comment1Message = [[[comment1 objectForKey:@"message"] retain] autorelease];

// Try posting the same comment to the same status update. We need to clear its ID first.
[comment1 removeObjectForKey:@"id"];
id comment2 = [self postComment:comment1 toStatusID:statusID];

NSString *comment1ID = [comment1 objectForKey:@"id"];
NSString *comment2ID = [comment2 objectForKey:@"id"];
NSString *comment1Message = [comment1 objectForKey:@"message"];
NSString *comment2Message = [comment2 objectForKey:@"message"];

STAssertFalse([comment1ID isEqualToString:comment2ID], @"ended up with the same comment");
Expand All @@ -315,16 +315,15 @@ - (void)testCommentRoundTrip
- (id)postEvent
{
id<FBGraphObject> event = [FBGraphObject graphObject];
[event setObject:[NSString stringWithFormat:@"My event on %@", [NSDate date]]
NSDate *startTime = [NSDate dateWithTimeIntervalSinceNow:24 * 3600];
[event setObject:[NSString stringWithFormat:@"My event on %@", startTime]
forKey:@"name"];
[event setObject:@"This is a great event. You should all come."
forKey:@"description"];
NSDate *startTime = [NSDate dateWithTimeIntervalSinceNow:24 * 3600];
NSDate *endTime = [NSDate dateWithTimeInterval:3600 sinceDate:startTime];
[event setObject:startTime forKey:@"start_time"];
[event setObject:endTime forKey:@"end_time"];
[event setObject:@"My house" forKey:@"location"];
[event setObject:@"CLOSED" forKey:@"privacy"];

return [self batchedPostAndGetWithSession:self.defaultTestSession
graphPath:@"me/events"
Expand Down
8 changes: 1 addition & 7 deletions src/tests/FBTests.m
Expand Up @@ -250,15 +250,9 @@ - (id)batchedPostAndGetWithSession:(FBSession*)session
}
batchEntryName:@"postRequest"];

// Get the thing. We know this is being used mostly for round-tripping objects, including
// things with timestamps, so request Unix timestamp format so we don't need to worry about
// date parsing just to test other functionality..
NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
@"U", @"date_format",
nil];
FBRequest *getRequest = [[FBRequest alloc] initWithSession:session
graphPath:@"{result=postRequest:$.id}"
parameters:parameters
parameters:nil
HTTPMethod:nil];
__block id createdObject = nil;
__block FBTestBlocker *blocker = [[FBTestBlocker alloc] init];
Expand Down

0 comments on commit 77984b8

Please sign in to comment.