|
| 1 | +// |
| 2 | +// NSDateFormatterTest.m |
| 3 | +// NUSurveyor |
| 4 | +// |
| 5 | +// Created by John Dzak on 1/15/13. |
| 6 | +// Copyright (c) 2013 Northwestern University. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "NSDateFormatterTest.h" |
| 10 | +#import "NSDateFormatter+NUAdditions.h" |
| 11 | +@implementation NSDateFormatterTest |
| 12 | + |
| 13 | +- (void)testRFC3339Formatter { |
| 14 | + |
| 15 | + // date-fullyear = 4DIGIT |
| 16 | + // date-month = 2DIGIT ; 01-12 |
| 17 | + // date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on |
| 18 | + // ; month/year |
| 19 | + // time-hour = 2DIGIT ; 00-23 |
| 20 | + // time-minute = 2DIGIT ; 00-59 |
| 21 | + // time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second |
| 22 | + // ; rules |
| 23 | + // time-secfrac = "." 1*DIGIT |
| 24 | + // time-numoffset = ("+" / "-") time-hour ":" time-minute |
| 25 | + // time-offset = "Z" / time-numoffset |
| 26 | + // partial-time = time-hour ":" time-minute ":" time-second |
| 27 | + // [time-secfrac] |
| 28 | + // full-date = date-fullyear "-" date-month "-" date-mday |
| 29 | + // full-time = partial-time time-offset |
| 30 | + // date-time = full-date "T" full-time |
| 31 | + |
| 32 | + NSDateFormatter* f = [NSDateFormatter rfc3339DateFormatter]; |
| 33 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18:00Z"], nil); |
| 34 | + |
| 35 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18:00+02:00"], nil); |
| 36 | + |
| 37 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18:00-02:00"], nil); |
| 38 | +} |
| 39 | + |
| 40 | +- (void)testDateTimeResponseFormatter { |
| 41 | + NSDateFormatter* f = [NSDateFormatter dateTimeResponseFormatter]; |
| 42 | + |
| 43 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18Z"], nil); |
| 44 | + |
| 45 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18+02:00"], nil); |
| 46 | + |
| 47 | + STAssertNotNil([f dateFromString:@"2012-08-06T05:18-02:00"], nil); |
| 48 | +} |
| 49 | + |
| 50 | +- (void)testDateResponseFormatter { |
| 51 | + NSDateFormatter* f = [NSDateFormatter dateResponseFormatter]; |
| 52 | + |
| 53 | + STAssertNotNil([f dateFromString:@"2012-08-06"], nil); |
| 54 | +} |
| 55 | + |
| 56 | +- (void)testTimeResponseFormatter { |
| 57 | + NSDateFormatter* f = [NSDateFormatter timeResponseFormatter]; |
| 58 | + |
| 59 | + STAssertNotNil([f dateFromString:@"05:18"], nil); |
| 60 | +} |
| 61 | + |
| 62 | +@end |
0 commit comments