Source

ISO 8601 parser/unparser / unparse-date.m

Diff from to

unparse-date.m

 	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;
-		printf("%s\n", [[NSString stringWithFormat:@"%@:\t%@", arg, [formatter stringFromDate:[formatter dateFromString:arg timeZone:&timeZone] timeZone:timeZone]] UTF8String]);
+		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];