Skip to content

Instantly share code, notes, and snippets.

@jazzz13 jazzz13/FADateTest.m
Created May 15, 2019

Embed
What would you like to do?
//
// FADateTest.m
// frank-ios
//
// Created by Ринат Муртазин on 20/10/15.
// Copyright © 2015 Frank. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "NSDate+FAExtension.h"
NSDate *dateByParams(NSInteger Y, NSInteger M, NSInteger D, NSInteger h, NSInteger m)
{
NSDateComponents *comps = [NSDateComponents new];
[comps setYear:Y];
[comps setMonth:M];
[comps setDay:D];
[comps setHour:h];
[comps setMinute:m];
return [[NSCalendar currentCalendar] dateFromComponents:comps];
}
@interface FADateTest : XCTestCase
@end
@implementation FADateTest
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)test_minutes
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 10, 30);
NSDate *date = dateByParams(2015, 10, 20, 10, 31);
XCTAssertEqualObjects(@"1 minute ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"1m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 10, 30);
XCTAssertEqualObjects(@"1 minute ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"1m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 10, 29);
XCTAssertEqualObjects(@"1 minute ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertEqualObjects(@"1m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
date = dateByParams(2015, 10, 20, 10, 28);
XCTAssertEqualObjects(@"2 minutes ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertEqualObjects(@"2m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
date = dateByParams(2015, 10, 20, 10, 00);
XCTAssertEqualObjects(@"30 minutes ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertEqualObjects(@"30m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
date = dateByParams(2015, 10, 20, 9, 59);
XCTAssertEqualObjects(@"31 minutes ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertEqualObjects(@"31m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
date = dateByParams(2015, 10, 20, 9, 31);
XCTAssertEqualObjects(@"59 minutes ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertEqualObjects(@"59m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
date = dateByParams(2015, 10, 20, 9, 30);
XCTAssertNotEqualObjects(@"59 minutes ago", [date fa_momentDescriptionRelativeDate:relativeDate ]);
XCTAssertNotEqualObjects(@"59m", [date fa_momentDescriptionShort:YES relativeDate:relativeDate ]);
}
- (void)test_hours
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 10, 30);
NSDate *date = nil;
date = dateByParams(2015, 10, 20, 9, 31);
XCTAssertNotEqualObjects(@"1 hour ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertNotEqualObjects(@"1h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 9, 30);
XCTAssertEqualObjects(@"1 hour ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"1h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 9, 29);
XCTAssertEqualObjects(@"1 hour ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"1h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 8, 31);
XCTAssertEqualObjects(@"1 hour ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"1h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 8, 30);
XCTAssertEqualObjects(@"2 hours ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"2h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 8, 29);
XCTAssertEqualObjects(@"2 hours ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"2h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 6, 30);
XCTAssertEqualObjects(@"4 hours ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"4h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 10, 31);
XCTAssertEqualObjects(@"23 hours ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"23h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 10, 30);
XCTAssertNotEqualObjects(@"24 hours ago", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertNotEqualObjects(@"24h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
}
- (void)test_yesterday
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 15, 30);
NSDate *date = nil;
date = dateByParams(2015, 10, 19, 9, 11);
XCTAssertEqualObjects(@"Yesterday at 9:11am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 9:11am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 11, 3);
XCTAssertEqualObjects(@"Yesterday at 11:03am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 11:03am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 12, 0);
XCTAssertEqualObjects(@"Yesterday at 12:00pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 12:00pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 13, 59);
XCTAssertEqualObjects(@"Yesterday at 1:59pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 1:59pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 15, 30);
XCTAssertEqualObjects(@"Yesterday at 3:30pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 3:30pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 15, 31);
XCTAssertNotEqualObjects(@"Yesterday at 3:30pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertNotEqualObjects(@"Yesterday, 3:30am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 1, 1);
XCTAssertEqualObjects(@"Yesterday at 1:01am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 1:01am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 19, 0, 0);
XCTAssertEqualObjects(@"Yesterday at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 12:00am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
relativeDate = dateByParams(2015, 11, 1, 15, 30);
date = dateByParams(2015, 10, 31, 13, 15);
XCTAssertEqualObjects(@"Yesterday at 1:15pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 1:15pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
relativeDate = dateByParams(2016, 1, 1, 15, 30);
date = dateByParams(2015, 12, 31, 13, 15);
XCTAssertEqualObjects(@"Yesterday at 1:15pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 1:15pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
}
- (void)test_weekDays
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 10, 30);
NSDate *date = nil;
date = dateByParams(2015, 10, 18, 6, 18);
XCTAssertEqualObjects(@"Sunday at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Sun, 6:18am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 17, 14, 18);
XCTAssertEqualObjects(@"Saturday at 2:18pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Sat, 2:18pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 16, 23, 1);
XCTAssertEqualObjects(@"Friday at 11:01pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Fri, 11:01pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 15, 0, 0);
XCTAssertEqualObjects(@"Thursday at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Thu, 12:00am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 14, 23, 59);
XCTAssertEqualObjects(@"Wednesday at 11:59pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Wed, 11:59pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
relativeDate = dateByParams(2016, 1, 2, 15, 30);
date = dateByParams(2015, 12, 31, 13, 15);
XCTAssertEqualObjects(@"Thursday at 1:15pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Thu, 1:15pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 12, 27, 13, 15);
XCTAssertEqualObjects(@"Sunday at 1:15pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Sun, 1:15pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
}
- (void)test_full_date
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 10, 30);
NSDate *date = nil;
date = dateByParams(2015, 10, 13, 6, 18);
XCTAssertEqualObjects(@"October 13 at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 13", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 12, 6, 18);
XCTAssertEqualObjects(@"October 12 at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 12", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"October 12 at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 12", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 1, 6, 18);
XCTAssertEqualObjects(@"October 1 at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 01", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 5, 12, 15, 1);
XCTAssertEqualObjects(@"May 12 at 3:01pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"May 12", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"May 12 at 3:01pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"May 12", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2014, 10, 1, 6, 18);
XCTAssertEqualObjects(@"October 1, 2014 at 6:18am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 01, 2014", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2013, 5, 12, 15, 1);
XCTAssertEqualObjects(@"May 12, 2013 at 3:01pm", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"May 12, 2013", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
relativeDate = dateByParams(2016, 1, 9, 0, 0);
date = dateByParams(2015, 12, 8, 0, 0);
XCTAssertEqualObjects(@"December 8, 2015 at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Dec 08, 2015", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"December 8, 2015 at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Dec 08, 2015", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 12, 10, 0, 0);
XCTAssertEqualObjects(@"December 10, 2015 at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Dec 10, 2015", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"December 10, 2015 at 12:00am", [date fa_momentDescriptionRelativeDate:relativeDate]);
XCTAssertEqualObjects(@"Dec 10, 2015", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
}
- (void)test_is_yesterday
{
NSDate *relativeDate = dateByParams(2015, 10, 20, 10, 30);
NSDate *date = nil;
date = dateByParams(2015, 10, 19, 6, 18);
XCTAssert([date fa_isYesterdayRelativeDate:relativeDate]);
date = dateByParams(2015, 10, 18, 6, 18);
XCTAssertFalse([date fa_isYesterdayRelativeDate:relativeDate]);
date = dateByParams(2015, 10, 20, 6, 18);
XCTAssertFalse([date fa_isYesterdayRelativeDate:relativeDate]);
relativeDate = dateByParams(2016, 2, 1, 1, 1);
date = dateByParams(2016, 1, 31, 1, 1);
XCTAssert([date fa_isYesterdayRelativeDate:relativeDate]);
date = dateByParams(2016, 1, 30, 1, 1);
XCTAssertFalse([date fa_isYesterdayRelativeDate:relativeDate]);
relativeDate = dateByParams(2016, 1, 1, 1, 1);
date = dateByParams(2015, 12, 31, 1, 1);
XCTAssert([date fa_isYesterdayRelativeDate:relativeDate]);
date = dateByParams(2015, 12, 30, 1, 1);
XCTAssertFalse([date fa_isYesterdayRelativeDate:relativeDate]);
}
- (void)test_funnydate
{
NSDate *relativeDate = dateByParams(2015, 11, 27, 17, 30);
NSDate *date = nil;
date = dateByParams(2015, 11, 27, 13, 13);
XCTAssertEqualObjects(@"4h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 27, 11, 11);
XCTAssertEqualObjects(@"6h", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 26, 11, 3);
XCTAssertEqualObjects(@"Yesterday, 11:03am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"Yesterday, 11:03am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 25, 6, 18);
XCTAssertEqualObjects(@"Wed, 6:18am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 24, 14, 18);
XCTAssertEqualObjects(@"Tue, 2:18pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"Tue, 2:18pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 23, 23, 1);
XCTAssertEqualObjects(@"Mon, 11:01pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 22, 0, 0);
XCTAssertEqualObjects(@"Sun, 12:00am", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 21, 23, 59);
XCTAssertEqualObjects(@"Sat, 11:59pm", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 20, 13, 15);
XCTAssertEqualObjects(@"Nov 20", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"Nov 20", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 19, 13, 15);
XCTAssertEqualObjects(@"Nov 19", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 18, 6, 18);
XCTAssertEqualObjects(@"Nov 18", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 18, 6, 18);
XCTAssertEqualObjects(@"Nov 18", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 17, 6, 18);
XCTAssertEqualObjects(@"Nov 17", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 11, 16, 6, 18);
XCTAssertEqualObjects(@"Nov 16", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2015, 10, 27, 17, 30);
XCTAssertEqualObjects(@"Oct 27", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
XCTAssertEqualObjects(@"Oct 27", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
date = dateByParams(2014, 10, 27, 17, 30);
XCTAssertEqualObjects(@"Oct 27, 2014", [date fa_momentDescriptionShort:YES relativeDate:relativeDate]);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.