Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b8117a9

Browse files
日期解析 fix
1 parent a64b2c8 commit b8117a9

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

‎Coding_iOS/Coding_Enterprise_iOS-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>2.9.7</string>
20+
<string>2.9.8</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -28,7 +28,7 @@
2828
</dict>
2929
</array>
3030
<key>CFBundleVersion</key>
31-
<string>2.9.7.20181022.3</string>
31+
<string>2.9.8.20181031.1</string>
3232
<key>ITSAppUsesNonExemptEncryption</key>
3333
<false/>
3434
<key>LSApplicationQueriesSchemes</key>

‎Coding_iOS/Coding_iOS-Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>5.4.2</string>
20+
<string>5.4.3</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -37,7 +37,7 @@
3737
</dict>
3838
</array>
3939
<key>CFBundleVersion</key>
40-
<string>5.4.2.20181022.3</string>
40+
<string>5.4.3.20181031.1</string>
4141
<key>ITSAppUsesNonExemptEncryption</key>
4242
<false/>
4343
<key>LSApplicationQueriesSchemes</key>

‎Coding_iOS/Util/OC_Category/NSObject+ObjectMap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#define OMDateFormat @"yyyy-MM-dd'T'HH:mm:ss.SSS"
1313
#define OMTimeZone @"UTC"
14+
#define EADateFormat @"yyyy-MM-dd HH:mm:ss"
1415

1516
@interface NSObject (ObjectMap)
1617

@@ -52,4 +53,4 @@
5253
@interface SOAPObject : NSObject
5354
@property (nonatomic, retain) id Header;
5455
@property (nonatomic, retain) id Body;
55-
@end
56+
@end

‎Coding_iOS/Util/OC_Category/NSObject+ObjectMap.m

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,27 @@ -(id)getNodeValue:(NSString *)node fromXML:(NSString *)xml {
187187
}
188188

189189
#pragma mark - Dictionary to Object
190+
+ (NSDate *)p_dateFromObj:(id)obj{
191+
NSDate *date;
192+
if ([obj isKindOfClass:[NSNumber class]]) {
193+
// 1970年的long型数字
194+
NSNumber *timeSince1970 = (NSNumber *)obj;
195+
NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue/1000;
196+
date = [NSDate dateWithTimeIntervalSince1970:timeSince1970TimeInterval];
197+
}else if ([obj isKindOfClass:[NSString class]]){
198+
// 日期字符串
199+
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
200+
[formatter setDateFormat:OMDateFormat];
201+
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]];
202+
date = [formatter dateFromString:(NSString *)obj];
203+
if (!date) {
204+
[formatter setDateFormat:EADateFormat];
205+
date = [formatter dateFromString:(NSString *)obj];
206+
}
207+
}
208+
return date;
209+
}
210+
190211
+(id)objectOfClass:(NSString *)object fromJSON:(NSDictionary *)dict {
191212
if (!dict || ![dict isKindOfClass:[NSDictionary class]]) {
192213
return nil;
@@ -231,21 +252,7 @@ +(id)objectOfClass:(NSString *)object fromJSON:(NSDictionary *)dict {
231252

232253
// check if NSDate or not
233254
if ([classType isEqualToString:@"T@\"NSDate\""]) {
234-
// 1970年的long型数字
235-
NSObject *obj = [dict objectForKey:key];
236-
if ([obj isKindOfClass:[NSNumber class]]) {
237-
NSNumber *timeSince1970 = (NSNumber *)obj;
238-
NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue/1000;
239-
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeSince1970TimeInterval];
240-
[newObject setValue:date forKey:propertyName];
241-
}else{
242-
// 日期字符串
243-
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
244-
[formatter setDateFormat:OMDateFormat];
245-
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]];
246-
NSString *dateString = [[dict objectForKey:key] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
247-
[newObject setValue:[formatter dateFromString:dateString] forKey:propertyName];
248-
}
255+
[newObject setValue:[self p_dateFromObj:[dict objectForKey:key]] forKey:propertyName];
249256
}
250257
else {
251258
if ([dict objectForKey:key] != [NSNull null]) {
@@ -370,22 +377,7 @@ +(NSMutableArray *)arrayMapFromArray:(NSArray *)nestedArray forPropertyName:(NSS
370377
NSString *classType = [self typeFromProperty:property];
371378
// check if NSDate or not
372379
if ([classType isEqualToString:@"T@\"NSDate\""]) {
373-
// 1970年的long型数字
374-
NSObject *obj = [nestedArray[xx] objectForKey:newKey];
375-
if ([obj isKindOfClass:[NSNumber class]]) {
376-
NSNumber *timeSince1970 = (NSNumber *)obj;
377-
NSTimeInterval timeSince1970TimeInterval = timeSince1970.doubleValue/1000;
378-
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeSince1970TimeInterval];
379-
[nestedObj setValue:date forKey:tempNewKey];
380-
}else{
381-
// 日期字符串
382-
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
383-
[formatter setDateFormat:OMDateFormat];
384-
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:OMTimeZone]];
385-
386-
NSString *dateString = [[nestedArray[xx] objectForKey:newKey] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
387-
[nestedObj setValue:[formatter dateFromString:dateString] forKey:tempNewKey];
388-
}
380+
[nestedObj setValue:[self p_dateFromObj:[nestedArray[xx] objectForKey:newKey]] forKey:tempNewKey];
389381
}
390382
else {
391383
[nestedObj setValue:[nestedArray[xx] objectForKey:newKey] forKey:tempNewKey];

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /