Created
February 23, 2011 11:01
-
-
Save soffes/840291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
+ (NSDate *)dateFromISO8601String:(NSString *)string { | |
if (!string) { | |
return nil; | |
} | |
struct tm tm; | |
time_t t; | |
strptime([string cStringUsingEncoding:NSUTF8StringEncoding], "%Y-%m-%dT%H:%M:%S%z", &tm); | |
tm.tm_isdst = -1; | |
t = mktime(&tm); | |
return [NSDate dateWithTimeIntervalSince1970:t + [[NSTimeZone localTimeZone] secondsFromGMT]]; | |
} | |
- (NSString *)ISO8601String { | |
struct tm *timeinfo; | |
char buffer[80]; | |
time_t rawtime = [self timeIntervalSince1970] - [[NSTimeZone localTimeZone] secondsFromGMT]; | |
timeinfo = localtime(&rawtime); | |
strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S%z", timeinfo); | |
return [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)camelCaseString { | |
static NSRegularExpression *regex = nil; | |
if (!regex) { | |
regex = [[NSRegularExpression alloc] initWithPattern:@"(?:_)(.)" options:0 error:nil]; | |
} | |
// Use regex... | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment