@@ -134,7 +134,7 @@ static force_inline BOOL YYEncodingTypeIsCNumber(YYEncodingType type) {
134
134
// / Parse string to date.
135
135
static force_inline NSDate *YYNSDateFromString (__unsafe_unretained NSString *string) {
136
136
typedef NSDate * (^YYNSDateParseBlock)(NSString *string);
137
- #define kParserNum 32
137
+ #define kParserNum 34
138
138
static YYNSDateParseBlock blocks[kParserNum + 1 ] = {0 };
139
139
static dispatch_once_t onceToken;
140
140
dispatch_once (&onceToken, ^{
@@ -153,6 +153,8 @@ static force_inline BOOL YYEncodingTypeIsCNumber(YYEncodingType type) {
153
153
/*
154
154
2014-01-20 12:24:48
155
155
2014-01-20T12:24:48 // Google
156
+ 2014-01-20 12:24:48.000
157
+ 2014-01-20T12:24:48.000
156
158
*/
157
159
NSDateFormatter *formatter1 = [[NSDateFormatter alloc ] init ];
158
160
formatter1.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
@@ -163,6 +165,16 @@ static force_inline BOOL YYEncodingTypeIsCNumber(YYEncodingType type) {
163
165
formatter2.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
164
166
formatter2.timeZone = [NSTimeZone timeZoneForSecondsFromGMT: 0 ];
165
167
formatter2.dateFormat = @" yyyy-MM-dd HH:mm:ss" ;
168
+
169
+ NSDateFormatter *formatter3 = [[NSDateFormatter alloc ] init ];
170
+ formatter3.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
171
+ formatter3.timeZone = [NSTimeZone timeZoneForSecondsFromGMT: 0 ];
172
+ formatter3.dateFormat = @" yyyy-MM-dd'T'HH:mm:ss.SSS" ;
173
+
174
+ NSDateFormatter *formatter4 = [[NSDateFormatter alloc ] init ];
175
+ formatter4.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
176
+ formatter4.timeZone = [NSTimeZone timeZoneForSecondsFromGMT: 0 ];
177
+ formatter4.dateFormat = @" yyyy-MM-dd HH:mm:ss.SSS" ;
166
178
167
179
blocks[19 ] = ^(NSString *string) {
168
180
if ([string characterAtIndex: 10 ] == ' T' ) {
@@ -171,30 +183,55 @@ static force_inline BOOL YYEncodingTypeIsCNumber(YYEncodingType type) {
171
183
return [formatter2 dateFromString: string];
172
184
}
173
185
};
186
+
187
+ blocks[23 ] = ^(NSString *string) {
188
+ if ([string characterAtIndex: 10 ] == ' T' ) {
189
+ return [formatter3 dateFromString: string];
190
+ } else {
191
+ return [formatter4 dateFromString: string];
192
+ }
193
+ };
174
194
}
175
195
176
196
{
177
197
/*
178
198
2014-01-20T12:24:48Z // Github, Apple
179
199
2014-01-20T12:24:48+0800 // Facebook
180
200
2014-01-20T12:24:48+12:00 // Google
201
+ 2014-01-20T12:24:48.000Z
202
+ 2014-01-20T12:24:48.000+0800
203
+ 2014-01-20T12:24:48.000+12:00
181
204
*/
182
205
NSDateFormatter *formatter = [NSDateFormatter new ];
183
206
formatter.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
184
207
formatter.dateFormat = @" yyyy-MM-dd'T'HH:mm:ssZ" ;
208
+
209
+ NSDateFormatter *formatter2 = [NSDateFormatter new ];
210
+ formatter2.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
211
+ formatter2.dateFormat = @" yyyy-MM-dd'T'HH:mm:ss.SSSZ" ;
212
+
185
213
blocks[20 ] = ^(NSString *string) { return [formatter dateFromString: string]; };
186
- blocks[24 ] = ^(NSString *string) { return [formatter dateFromString: string]; };
214
+ blocks[24 ] = ^(NSString *string) { return [formatter dateFromString: string]?: [formatter2 dateFromString: string] ; };
187
215
blocks[25 ] = ^(NSString *string) { return [formatter dateFromString: string]; };
216
+ blocks[28 ] = ^(NSString *string) { return [formatter2 dateFromString: string]; };
217
+ blocks[29 ] = ^(NSString *string) { return [formatter2 dateFromString: string]; };
188
218
}
189
219
190
220
{
191
221
/*
192
222
Fri Sep 04 00:12:21 +0800 2015 // Weibo, Twitter
223
+ Fri Sep 04 00:12:21.000 +0800 2015
193
224
*/
194
225
NSDateFormatter *formatter = [NSDateFormatter new ];
195
226
formatter.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
196
227
formatter.dateFormat = @" EEE MMM dd HH:mm:ss Z yyyy" ;
228
+
229
+ NSDateFormatter *formatter2 = [NSDateFormatter new ];
230
+ formatter2.locale = [[NSLocale alloc ] initWithLocaleIdentifier: @" en_US_POSIX" ];
231
+ formatter2.dateFormat = @" EEE MMM dd HH:mm:ss.SSS Z yyyy" ;
232
+
197
233
blocks[30 ] = ^(NSString *string) { return [formatter dateFromString: string]; };
234
+ blocks[34 ] = ^(NSString *string) { return [formatter2 dateFromString: string]; };
198
235
}
199
236
});
200
237
if (!string) return nil ;
0 commit comments