/
NSDate+Escort.h
190 lines (113 loc) · 4.38 KB
/
NSDate+Escort.h
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// LICENSE : MIT
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSDate (Escort)
#pragma mark - Setting default calendar
/**
Returns the calendarIdentifier of calendars that is used by this library for date calculation.
@see AZ_setDefaultCalendarIdentifier: for more details.
*/
+ (NSString * _Nullable)AZ_defaultCalendarIdentifier;
/**
Sets the calendarIdentifier of calendars that is used by this library for date calculation.
You can specify any calendarIdentifiers predefined by NSLocale. If you provide nil, the library uses
[NSCalendar currentCalendar]. Default value is nil.
You can't provide individual calendars for individual date objects. If you need to perform such
complicated date calculations, you should rather create calendars on your own.
*/
+ (void)AZ_setDefaultCalendarIdentifier:(NSString * _Nullable)calendarIdentifier;
#pragma mark - Relative dates from the current date
+ (NSDate *)dateTomorrow;
+ (NSDate *)dateYesterday;
+ (NSDate *)dateWithDaysFromNow:(NSInteger) dDays;
+ (NSDate *)dateWithDaysBeforeNow:(NSInteger) dDays;
+ (NSDate *)dateWithHoursFromNow:(NSInteger) dHours;
+ (NSDate *)dateWithHoursBeforeNow:(NSInteger) dHours;
+ (NSDate *)dateWithMinutesFromNow:(NSInteger) dMinutes;
+ (NSDate *)dateWithMinutesBeforeNow:(NSInteger) dMinutes;
#pragma mark - Comparing dates
- (BOOL)isEqualToDateIgnoringTime:(NSDate *) otherDate;
- (BOOL)isToday;
- (BOOL)isTomorrow;
- (BOOL)isYesterday;
- (BOOL)isSameWeekAsDate:(NSDate *) aDate;
- (BOOL)isThisWeek;
- (BOOL)isNextWeek;
- (BOOL)isLastWeek;
- (BOOL)isSameMonthAsDate:(NSDate *) aDate;
- (BOOL)isThisMonth;
- (BOOL)isSameYearAsDate:(NSDate *) aDate;
- (BOOL)isThisYear;
- (BOOL)isNextYear;
- (BOOL)isLastYear;
- (BOOL)isEarlierThanDate:(NSDate *) aDate;
- (BOOL)isLaterThanDate:(NSDate *) aDate;
- (BOOL)isEarlierThanOrEqualDate:(NSDate *) aDate;
- (BOOL)isLaterThanOrEqualDate:(NSDate *) aDate;
- (BOOL)isInFuture;
- (BOOL)isInPast;
#pragma mark - Date roles
- (BOOL)isTypicallyWorkday;
- (BOOL)isTypicallyWeekend;
#pragma mark - Adjusting dates
- (NSDate *)dateByAddingYears:(NSInteger) dYears;
- (NSDate *)dateBySubtractingYears:(NSInteger) dYears;
- (NSDate *)dateByAddingMonths:(NSInteger) dMonths;
- (NSDate *)dateBySubtractingMonths:(NSInteger) dMonths;
- (NSDate *)dateByAddingDays:(NSInteger) dDays;
- (NSDate *)dateBySubtractingDays:(NSInteger) dDays;
- (NSDate *)dateByAddingHours:(NSInteger) dHours;
- (NSDate *)dateBySubtractingHours:(NSInteger) dHours;
- (NSDate *)dateByAddingMinutes:(NSInteger) dMinutes;
- (NSDate *)dateBySubtractingMinutes:(NSInteger) dMinutes;
- (NSDate *)dateByAddingSeconds:(NSInteger) dSeconds;
- (NSDate *)dateBySubtractingSeconds:(NSInteger) dSeconds;
- (NSDate *)dateAtStartOfDay;
- (NSDate *)dateAtStartOfNextDay;
- (NSDate *)dateAtStartOfWeek;
- (NSDate *)dateAtStartOfNextWeek;
- (NSDate *)dateAtStartOfMonth;
- (NSDate *)dateAtStartOfNextMonth;
- (NSDate *)dateAtStartOfYear;
- (NSDate *)dateAtStartOfNextYear;
#pragma mark - Retrieving intervals
- (NSInteger)secondsAfterDate:(NSDate *) aDate;
- (NSInteger)secondsBeforeDate:(NSDate *) aDate;
- (NSInteger)minutesAfterDate:(NSDate *) aDate;
- (NSInteger)minutesBeforeDate:(NSDate *) aDate;
- (NSInteger)hoursAfterDate:(NSDate *) aDate;
- (NSInteger)hoursBeforeDate:(NSDate *) aDate;
- (NSInteger)daysAfterDate:(NSDate *) aDate;
- (NSInteger)daysBeforeDate:(NSDate *) aDate;
- (NSInteger)monthsAfterDate:(NSDate *) aDate;
- (NSInteger)monthsBeforeDate:(NSDate *) aDate;
/**
* return distance days
*/
- (NSInteger)distanceInDaysToDate:(NSDate *) aDate;
#pragma mark amount
- (NSInteger)hoursOfDay;
- (NSInteger)daysOfMonth;
- (NSInteger)daysOfYear;
- (NSInteger)monthsOfYear;
#pragma mark - Decomposing dates
/**
* return nearest hour
*/
@property(readonly) NSInteger nearestHour;
@property(readonly) NSInteger hour;
@property(readonly) NSInteger minute;
@property(readonly) NSInteger seconds;
@property(readonly) NSInteger day;
@property(readonly) NSInteger month;
@property(readonly) NSInteger week;
// in the Gregorian calendar, n is 7 and Sunday is represented by 1.
@property(readonly) NSInteger weekday;
@property(readonly) NSInteger firstDayOfWeekday;
@property(readonly) NSInteger lastDayOfWeekday;
// e.g. 2nd Tuesday of the month == 2
@property(readonly) NSInteger nthWeekday;
@property(readonly) NSInteger year;
@property(readonly) NSInteger gregorianYear;
@end
NS_ASSUME_NONNULL_END