-
Notifications
You must be signed in to change notification settings - Fork 12
/
OMHHumanReadableDateTest.m
105 lines (80 loc) · 3.3 KB
/
OMHHumanReadableDateTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// OMHHumanReadableDateTest.m
// Clyppan
//
// Created by Ole Morten Halvorsen on 22/08/2009.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "OMHHumanReadableDateTest.h"
#import "OMHHumanReadableDate.h"
@implementation OMHHumanReadableDateTest
- (void) testLessThanAMinute
{
NSDate *date = [NSDate date];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"less than a minute ago", @"Less than a minute ago" );
}
- (void) test59SecondsAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 59];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"less than a minute ago", @"Less than a minute ago" );
}
- (void) test1MinuteAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 60];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"1 minute ago", @"1 Minute ago" );
}
- (void) test2Minutes59secondsAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 179];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"3 minutes ago", @"2 Minutes 59 seconds ago" );
}
- (void) test3MinutesAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 180];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"3 minutes ago", @"3 Minutes ago" );
}
- (void) test59MinutesAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - (59 * 60)];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"59 minutes ago", @"59 Minutes ago" );
}
- (void) test1HourAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 3600];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"1 hour ago", @"1 hour ago" );
}
- (void) test2HoursAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - 7199];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"2 hours ago", @"2 hours ago" );
}
- (void) test1DayAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - (3600 * 24)];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"1 day ago", @"1 day ago" );
}
- (void) test2DaysAgo
{
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:now - (2 * 3600 * 24)];
NSString *string = [OMHHumanReadableDate dateToHumanReadableString:date];
STAssertEqualObjects( string, @"2 days ago", @"2 days ago" );
}
@end