Permalink
Browse files

Use standard JSON date format in documents & doc IDs.

  • Loading branch information...
1 parent e8a8271 commit 8f4bb367e2829a64ed097ca10faa06f404d61612 @snej snej committed Sep 2, 2011
Showing with 8 additions and 5 deletions.
  1. +8 −5 Source/RootViewController.m
@@ -236,18 +236,21 @@ -(void)textFieldDidEndEditing:(UITextField *)textField {
}
[addItemTextField setText:nil];
+ // Get the current date+time as a string in standard JSON format:
+ NSString* dateString = [RESTBody JSONObjectWithDate: [NSDate date]];
+
// Construct a unique document ID that will sort chronologically:
CFUUIDRef uuid = CFUUIDCreate(nil);
NSString *guid = (NSString*)CFUUIDCreateString(nil, uuid);
CFRelease(uuid);
- NSString *docId = [NSString stringWithFormat:@"%f-%@", CFAbsoluteTimeGetCurrent(), guid];
+ NSString *docId = [NSString stringWithFormat:@"%@-%@", dateString, guid];
[guid release];
// Create the new document's properties:
- NSDictionary *inDocument = [NSDictionary dictionaryWithObjectsAndKeys:text, @"text"
- , [NSNumber numberWithBool:NO], @"check"
- , [[NSDate date] description], @"created_at"
- , nil];
+ NSDictionary *inDocument = [NSDictionary dictionaryWithObjectsAndKeys:text, @"text",
+ [NSNumber numberWithBool:NO], @"check",
+ dateString, @"created_at",
+ nil];
// Save the document, asynchronously:
CouchDocument* doc = [database documentWithID: docId];

0 comments on commit 8f4bb36

Please sign in to comment.