Revision 29cc4957 Classes/ComputeModel.m

b/Classes/ComputeModel.m
59 59
#pragma mark -
60 60
#pragma mark Date Parser
61 61

  
62
+ (NSDate *)dateFromString:(NSString *)dateString {
63
    return nil; // temporarily removing date parsing for performance
64
    
65
    /*
66
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
67
	[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
68
	// example: 2009-11-04T19:46:20.192723
62
+ (NSDate *)dateFromString:(NSString *)dateString {   
63
    // example: 2009-11-04T19:46:20.192723
69 64
    // 2010-01-26T12:07:32-06:00
65
    NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
66
	NSDateFormatter *dateFormatter = [threadDict objectForKey:@"iso8601DateFormatter"];
67
    if (!dateFormatter) {
68
        dateFormatter = [[NSDateFormatter alloc] init];
69
        [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
70
        [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"];
71
        [threadDict setObject:dateFormatter forKey:@"iso8601DateFormatter"];
72
        [dateFormatter release];
73
    }
74

  
75
    return [dateFormatter dateFromString:[dateString stringByReplacingOccurrencesOfString:@":" 
76
                                                                               withString:@"" 
77
                                                                                  options:NSBackwardsSearch 
78
                                                                                    range:NSMakeRange(([dateString length] - 3), 1)]];
79
}
70 80

  
71
    // this is nasty, but -06:00 is not a valid timezone format.  converting to -0600 style
72
    dateString = [NSString stringWithFormat:@"%@%@", [dateString substringToIndex:22], [dateString substringFromIndex:23]];
73
    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'H:mm:ssZ"];
81
+ (NSDate *)dateFromRFC1123String:(NSString *)dateString {
82
    NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
83
    NSDateFormatter *dateFormatter = [threadDict objectForKey:@"rfc1123DateFormatter"];
84
    if (!dateFormatter) {
85
        dateFormatter = [[NSDateFormatter alloc] init];
86
        [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
87
        [dateFormatter setDateFormat:@"eee, dd MMM yyyy HH:mm:ss 'GMT'"];
88
        [threadDict setObject:dateFormatter forKey:@"rfc1123DateFormatter"];
89
        [dateFormatter release];
90
    }
91
    return [dateFormatter dateFromString:dateString];
92
}
74 93

  
75
	NSDate *date = [dateFormatter dateFromString:dateString];
76
	[dateFormatter release];
77
	
78
	return date;
79
     */
94
+ (NSString *)localDateDescriptionFromDate:(NSDate *)date {
95
    NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
96
    NSDateFormatter *dateFormatterLocal = [threadDict objectForKey:@"dateFormatterLocal"];
97
    if (!dateFormatterLocal) {
98
        dateFormatterLocal = [[NSDateFormatter alloc] init];
99
        [dateFormatterLocal setTimeZone:[NSTimeZone localTimeZone]];
100
        [dateFormatterLocal setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
101
        [threadDict setObject:dateFormatterLocal forKey:@"dateFormatterLocal"];
102
        [dateFormatterLocal release];
103
    }
104
    return [dateFormatterLocal stringFromDate:date];
80 105
}
81 106

  
82 107
- (NSDate *)dateFromString:(NSString *)dateString {

Also available in: Unified diff