NSDate+CommonExtension.h
2.93 KB
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
/*
Erica Sadun, http://ericasadun.com
iPhone Developer's Cookbook 3.x and beyond
BSD License, Use at your own risk
*/
/*
该NSDate类别的地址如下:
https://github.com/erica/NSDate-Extensions
该文件是最新版本。与上一版本主要的改动是两点:
1.接口中的NSUInteger类型的传入参数改为NSInteger。(防止传入负数的错误)
2.添加了新的接口:
- (BOOL)bba_isSameWeekAsDate:(NSDate *)aDate;
- (BOOL)bba_isThisWeek;
- (BOOL)bba_isTypicallyWorkday;
- (BOOL)bba_isTypicallyWeekend;
---zxh
*/
#import <Foundation/Foundation.h>
#define BBA_MINUTE 60
#define BBA_HOUR 3600
#define BBA_DAY 86400
#define BBA_WEEK 604800
#define BBA_YEAR 31556926
@interface NSDate (CommonExtension)
// Relative dates from the current date
+ (NSDate *)bba_dateTomorrow;
+ (NSDate *)bba_dateYesterday;
+ (NSDate *)bba_dateWithDaysFromNow:(NSInteger)days;
+ (NSDate *)bba_dateWithDaysBeforeNow:(NSInteger)days;
+ (NSDate *)bba_dateWithHoursFromNow:(NSInteger)dHours;
+ (NSDate *)bba_dateWithHoursBeforeNow:(NSInteger)dHours;
+ (NSDate *)bba_dateWithMinutesFromNow:(NSInteger)dMinutes;
+ (NSDate *)bba_dateWithMinutesBeforeNow:(NSInteger)dMinutes;
// Comparing dates
- (BOOL)bba_isEqualToDateIgnoringTime:(NSDate *)aDate;
- (BOOL)bba_isToday;
- (BOOL)bba_isTomorrow;
- (BOOL)bba_isYesterday;
- (BOOL)bba_isSameWeekAsDate:(NSDate *)aDate;
- (BOOL)bba_isThisWeek;
- (BOOL)bba_isNextWeek;
- (BOOL)bba_isLastWeek;
- (BOOL)bba_isSameMonthAsDate:(NSDate *)aDate;
- (BOOL)bba_isThisMonth;
- (BOOL)bba_isSameYearAsDate:(NSDate *)aDate;
- (BOOL)bba_isThisYear;
- (BOOL)bba_isNextYear;
- (BOOL)bba_isLastYear;
- (BOOL)bba_isEarlierThanDate:(NSDate *)aDate;
- (BOOL)bba_isLaterThanDate:(NSDate *)aDate;
// Date roles
- (BOOL)bba_isTypicallyWorkday;
- (BOOL)bba_isTypicallyWeekend;
// Adjusting dates
- (NSDate *)bba_dateByAddingDays:(NSInteger)dDays;
- (NSDate *)bba_dateBySubtractingDays:(NSInteger)dDays;
- (NSDate *)bba_dateByAddingHours:(NSInteger)dHours;
- (NSDate *)bba_dateBySubtractingHours:(NSInteger)dHours;
- (NSDate *)bba_dateByAddingMinutes:(NSInteger)dMinutes;
- (NSDate *)bba_dateBySubtractingMinutes:(NSInteger)dMinutes;
- (NSDate *)bba_dateAtStartOfDay;
// Retrieving intervals
- (NSInteger)bba_minutesAfterDate:(NSDate *)aDate;
- (NSInteger)bba_minutesBeforeDate:(NSDate *)aDate;
- (NSInteger)bba_hoursAfterDate:(NSDate *)aDate;
- (NSInteger)bba_hoursBeforeDate:(NSDate *)aDate;
- (NSInteger)bba_daysAfterDate:(NSDate *)aDate;
- (NSInteger)bba_daysBeforeDate:(NSDate *)aDate;
- (NSTimeInterval)bba_daysDecimalAfterDate:(NSDate *)aDate;
- (NSTimeInterval)bba_hoursDecimalAfterDate:(NSDate *)aDate;
+ (long)bba_timeSecondsSince1970;
// Decomposing dates
- (NSInteger)bba_nearestHour;
- (NSInteger)bba_hour;
- (NSInteger)bba_minute;
- (NSInteger)bba_seconds;
- (NSInteger)bba_day;
- (NSInteger)bba_month;
- (NSInteger)bba_week;
- (NSInteger)bba_weekday;
- (NSInteger)bba_nthWeekday; // e.g. 2nd Tuesday of the month == 2
- (NSInteger)bba_year;
@end