Created
May 12, 2015 16:46
-
-
Save jeffleeismyhero/9c9e1f1b8490dc69bb53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import XCTest; | |
#import "FORMData.h" | |
#import "FORMField.h" | |
#import "FORMSection.h" | |
#import "FORMLayout.h" | |
#import "FORMDataSource.h" | |
#import "NSJSONSerialization+ANDYJSONFile.h" | |
#import "NSDate+HYPString.h" | |
#import "FORMNameInputValidator.h" | |
#import "FORMPhoneNumberInputValidator.h" | |
@interface FORMFieldTests : XCTestCase | |
@end | |
@implementation FORMFieldTests | |
- (void)testInitWithDictionary { | |
field = [[FORMField alloc] initWithDictionary:@{@"id": @"start_date", | |
@"title": @"Start date", | |
@"type": @"date", | |
@"minimum_date":@"2000-01-01T00:00:00.002Z", | |
@"maximum_date":@"2015-01-01T00:00:00.002Z", | |
@"value":@"2014-01-01T00:00:00.002Z", | |
@"size": @{@"width": @10, | |
@"height": @4} | |
} | |
position:1 | |
disabled:NO | |
disabledFieldsIDs:@[@"start_date"]]; | |
XCTAssertEqualObjects([field.minimumDate hyp_dateString], @"2000-01-01"); | |
XCTAssertEqualObjects([field.maximumDate hyp_dateString], @"2015-01-01"); | |
XCTAssertEqualObjects([field.value hyp_dateString], @"2014-01-01"); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSDate+HYPString.h" | |
static NSString * const HYPDateDefaultFormat = @"yyyy-MM-dd"; | |
static NSString * const HYPTimeDefaultFormat = @"HH:mm"; | |
static NSString * const HYPTimeRangeFormat = @"%@ - %@"; | |
@implementation NSDate (HYPString) | |
- (NSString *)hyp_timeString | |
{ | |
return [self hyp_dateStringWithFormat:HYPTimeDefaultFormat]; | |
} | |
- (NSString *)hyp_dateString | |
{ | |
return [self hyp_dateStringWithFormat:HYPDateDefaultFormat]; | |
} | |
- (NSString *)hyp_dateStringWithFormat:(NSString *)format | |
{ | |
NSDateFormatter *dateFormatter = [NSDateFormatter new]; | |
dateFormatter.dateFormat = format; | |
NSTimeZone *timezone = [NSTimeZone localTimeZone]; | |
NSInteger seconds = [timezone secondsFromGMTForDate:self]; | |
NSDate *localDate = [NSDate dateWithTimeInterval:seconds sinceDate:self]; | |
return [dateFormatter stringFromDate:localDate]; | |
} | |
- (NSString *)hyp_timeRangeStringToEndDate:(NSDate *)endDate | |
{ | |
return [self hyp_dateRangeStringToEndDate:endDate withFormat:HYPTimeDefaultFormat]; | |
} | |
- (NSString *)hyp_dateRangeStringToEndDate:(NSDate *)endDate | |
{ | |
return [self hyp_dateRangeStringToEndDate:endDate withFormat:HYPDateDefaultFormat]; | |
} | |
- (NSString *)hyp_dateRangeStringToEndDate:(NSDate *)endDate withFormat:(NSString *)format | |
{ | |
return [NSString stringWithFormat:HYPTimeRangeFormat, | |
[self hyp_dateStringWithFormat:format], | |
[endDate hyp_dateStringWithFormat:format]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment