fork download
  1. #import <objc/objc.h>
  2. #import <objc/Object.h>
  3. #import <Foundation/Foundation.h>
  4.  
  5. @interface TestObj : NSObject
  6. {
  7. int num;
  8. }
  9. - (void)foo;
  10. @end
  11.  
  12. @implementation TestObj
  13. - (NSDate *)parseRFC3339Date:(NSString *)date {
  14. NSDate *parsedDate = nil;
  15. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  16.  
  17. NSRange zRange = [date rangeOfString:@"Z"];
  18. if (zRange.length > 0 && zRange.location == date.length - 1) {
  19. [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
  20. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
  21. parsedDate = [dateFormatter dateFromString:date];
  22. if (parsedDate == nil) {
  23. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"];
  24. dateFormatter.lenient = YES;
  25. parsedDate = [dateFormatter dateFromString:date];
  26. }
  27. return parsedDate;
  28. } else {
  29.  
  30. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];
  31. parsedDate = [dateFormatter dateFromString:date];
  32. if (parsedDate == nil) {
  33. [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ"];
  34. dateFormatter.lenient = YES;
  35. parsedDate = [dateFormatter dateFromString:date];
  36. }
  37. return parsedDate;
  38. }
  39. }
  40.  
  41. int main()
  42. {
  43. id obj = [[TestObj alloc] init];
  44. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26+07:00"] == nil ? "Failure\n" : "Success\n");
  45. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3+07:00"] == nil ? "Failure\n" : "Success\n");;
  46. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3452+07:00"] == nil ? "Failure\n" : "Success\n");;
  47. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26-07:00"] == nil ? "Failure\n" : "Success\n");;
  48. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3-07:00"] == nil ? "Failure\n" : "Success\n");;
  49. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3452-07:00"] == nil ? "Failure\n" : "Success\n");;
  50. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3452Z"] == nil ? "Failure\n" : "Success\n");;
  51. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26.3Z"] == nil ? "Failure\n" : "Success\n");;
  52. printf([obj parseRFC3339Date:@"2007-05-01T15:43:26Z"] == nil ? "Failure\n" : "Success\n");;
  53. return 0;
  54. }
  55. @end
Success #stdin #stdout #stderr 0.04s 42864KB
stdin
Standard input is empty
stdout
Success
Success
Success
Success
Success
Success
Success
Success
Success
stderr
2016-04-29 09:05:10.819 prog[10946] autorelease called without pool for object (0x9d5bf90) of class GSSetEnumerator in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9df3f88) of class GSDictionaryKeyEnumerator in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9deb1a0) of class GSMutableDictionary in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9df5cc0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc04e8) of class GSCBufferString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9df3d58) of class GSCInlineString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9db0650) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc4280) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc05b0) of class GSCBufferString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc43f0) of class GSDictionaryKeyEnumerator in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc44c0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dc0280) of class GSCBufferString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9df3fe8) of class GSCInlineString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.820 prog[10946] autorelease called without pool for object (0x9dbb330) of class GSCInlineString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9ded8d0) of class GSMutableString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dcfe08) of class GSCInlineString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc0950) of class GSCInlineString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc4210) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9df51c0) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9db6c10) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc4518) of class NSArrayEnumerator in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9df4060) of class GSMutableDictionary in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dbb550) of class GSMutableDictionary in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc07c0) of class GSDictionaryKeyEnumerator in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dd09f8) of class GSMutableDictionary in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] WARNING - unable to create shared user defaults!
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc0768) of class GSCBufferString in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.821 prog[10946] autorelease called without pool for object (0x9dc0710) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9db2130) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9df2880) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9df44f0) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.823 prog[10946] autorelease called without pool for object (0x9dc68c0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.824 prog[10946] autorelease called without pool for object (0x9dbab40) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.824 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.824 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.824 prog[10946] autorelease called without pool for object (0x9ddafb0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.824 prog[10946] autorelease called without pool for object (0x9ddbea0) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9de7090) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9de9fc8) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.825 prog[10946] autorelease called without pool for object (0x9df8338) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9df8168) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9dfb508) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9df18f0) of class GSAbsTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.826 prog[10946] autorelease called without pool for object (0x9dfe3f0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9dfc5a8) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9dfb4d0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9df18f0) of class GSAbsTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.827 prog[10946] autorelease called without pool for object (0x9e00de8) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9dff1b0) of class NSGDate in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9dc06b8) of class NSLocale in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9df63f8) of class GSTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9dfb2e0) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9df18f0) of class GSAbsTimeZone in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.828 prog[10946] autorelease called without pool for object (0x9dfe158) of class GSAutoreleasedMemory in thread <NSThread: 0x9d62800>
2016-04-29 09:05:10.829 prog[10946] autorelease called without pool for object (0x9e00d50) of class NSGDate in thread <NSThread: 0x9d62800>