Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 60 lines (46 sloc) 1.644 kb
30d1577 Added NSString category, creates NSDates from github's date strings. …
Owain R Hunt authored
1 //
2 // NSString+UAGithubEngineUtilities.m
3 // UAGithubEngine
4 //
5 // Created by Owain Hunt on 08/04/2010.
6 // Copyright 2010 Owain R Hunt. All rights reserved.
7 //
8
9 #import "NSString+UAGithubEngineUtilities.h"
10
11
12 @implementation NSString(UAGithubEngineUtilities)
13
14 - (NSDate *)dateFromGithubDateString {
cfab3eb Preparing for JSON parsing. Modified CJSONScanner to return mutable d…
Owain R Hunt authored
15
3dab517 [NSString dateFromGithubDateString] now uses NSDateFormatters to ensu…
Owain R Hunt authored
16 NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
17 NSString *dateString = self;
18
af29851 Added date parsing for third (count 'em) date format in API. Enhancem…
Owain R Hunt authored
19 // Because Github returns three different date string formats throughout the API,
d94fadd Added remaining parsers for JSON API. Added new check in [NSString da…
Owain R Hunt authored
20 // we need to check how to process the string based on the format used
d31ac0c Dates now parsed correctly for all users, whether returning a single …
Owain R Hunt authored
21 if ([[self substringWithRange:NSMakeRange(10, 1)] isEqualToString:@"T"])
d94fadd Added remaining parsers for JSON API. Added new check in [NSString da…
Owain R Hunt authored
22 {
d31ac0c Dates now parsed correctly for all users, whether returning a single …
Owain R Hunt authored
23 if ([[self substringWithRange:NSMakeRange([self length] - 1, 1)] isEqualToString:@"Z"])
af29851 Added date parsing for third (count 'em) date format in API. Enhancem…
Owain R Hunt authored
24 {
0663c3c @tstevens NSString+UAGithubEngineUtilities now properly parses date formats ret…
tstevens authored
25 // eg 2010-05-23T21:26:03.921Z (UTC with milliseconds)
26 if([[self substringWithRange:NSMakeRange(19, 1)] isEqualToString:@"."]){
27 [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
28 // eg 2010-05-23T21:26:03Z (UTC without milliseconds)
29 } else {
30 [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
31 }
af29851 Added date parsing for third (count 'em) date format in API. Enhancem…
Owain R Hunt authored
32 }
33 else
34 // eg 2010-04-07T12:50:15-07:00
35 {
3dab517 [NSString dateFromGithubDateString] now uses NSDateFormatters to ensu…
Owain R Hunt authored
36 NSMutableString *newDate = [self mutableCopy];
37 [newDate deleteCharactersInRange:NSMakeRange(22, 1)];
38 [df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZ"];
39 [dateString release];
40 dateString = newDate;
af29851 Added date parsing for third (count 'em) date format in API. Enhancem…
Owain R Hunt authored
41 }
3dab517 [NSString dateFromGithubDateString] now uses NSDateFormatters to ensu…
Owain R Hunt authored
42 } else {
43 // eg 2010/07/28 21:21:00 +0100
44 [df setDateFormat:@"yyyy/MM/dd HH:mm:ss ZZZ"];
45 }
d94fadd Added remaining parsers for JSON API. Added new check in [NSString da…
Owain R Hunt authored
46
3dab517 [NSString dateFromGithubDateString] now uses NSDateFormatters to ensu…
Owain R Hunt authored
47 return [df dateFromString:dateString];
48
30d1577 Added NSString category, creates NSDates from github's date strings. …
Owain R Hunt authored
49 }
50
d94fadd Added remaining parsers for JSON API. Added new check in [NSString da…
Owain R Hunt authored
51
1111fa8 Added add/remove label methods for repositories.
Owain R Hunt authored
52 - (NSString *)encodedString
53 {
54 return (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)self, NULL, (CFStringRef)@";/?:@&=$+{}<>,", kCFStringEncodingUTF8);
55
56 }
57
58
30d1577 Added NSString category, creates NSDates from github's date strings. …
Owain R Hunt authored
59 @end
Something went wrong with that request. Please try again.