forked from boredzo/iso-8601-date-formatter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unparse-date.m
33 lines (27 loc) · 899 Bytes
/
unparse-date.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#import "ISO8601DateFormatter.h"
int main(int argc, const char **argv) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
ISO8601DateFormatter *formatter = [[[ISO8601DateFormatter alloc] init] autorelease];
formatter.format = ISO8601DateFormatCalendar;
BOOL forceUTC = NO;
while (argv[1]) {
if (strcmp(argv[1], "--include-time") == 0)
formatter.includeTime = YES;
else if (strcmp(argv[1], "--force-utc") == 0)
forceUTC = YES;
else
break;
--argc;
++argv;
}
while(--argc) {
NSString *arg = [NSString stringWithUTF8String:*++argv];
NSTimeZone *timeZone = nil;
NSDate *date = [formatter dateFromString:arg timeZone:&timeZone];
if (forceUTC)
timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
printf("%s\n", [[NSString stringWithFormat:@"%@:\t%@", arg, [formatter stringFromDate:date timeZone:timeZone]] UTF8String]);
}
[pool release];
return 0;
}