Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ba6ee59ae6e606ab3aff to your computer and use it in GitHub Desktop.
Save anonymous/ba6ee59ae6e606ab3aff to your computer and use it in GitHub Desktop.
From 21b6a8fbbb9d42bfb4f6b77a6c0bf89b40369012 Mon Sep 17 00:00:00 2001
From: Adam Alexander <adamalex@gmail.com>
Date: Wed, 11 Feb 2009 22:23:46 -0500
Subject: [PATCH] Added support for parsing an incoming datetime that includes time zone info
---
Classes/lib/Core/ObjectiveResourceDateFormatter.m | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/Classes/lib/Core/ObjectiveResourceDateFormatter.m b/Classes/lib/Core/ObjectiveResourceDateFormatter.m
index 096764f..5ee3c1b 100644
--- a/Classes/lib/Core/ObjectiveResourceDateFormatter.m
+++ b/Classes/lib/Core/ObjectiveResourceDateFormatter.m
@@ -12,6 +12,7 @@
@implementation ObjectiveResourceDateFormatter
static NSString *dateTimeFormatString = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
+static NSString *dateTimeZoneFormatString = @"yyyy-MM-dd'T'HH:mm:ssz";
static NSString *dateFormatString = @"yyyy-MM-dd";
@@ -36,8 +37,9 @@ static NSString *dateFormatString = @"yyyy-MM-dd";
+ (NSDate *)parseDateTime:(NSString *)dateTimeString {
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
+ NSString *format = ([dateTimeString hasSuffix:@"Z"]) ? dateTimeFormatString : dateTimeZoneFormatString;
[formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
- [formatter setDateFormat:dateTimeFormatString];
+ [formatter setDateFormat:format];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
return [formatter dateFromString:dateTimeString];
--
1.6.1.1+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment