From 98ecab7f5ecdb78f58154f02f5cabd06e5d74694 Mon Sep 17 00:00:00 2001 From: Zenon Date: Wed, 13 Feb 2019 14:15:58 +0800 Subject: [PATCH] add dayOfYear for NSDate --- YYKit/Base/Foundation/NSDate+YYAdd.h | 1 + YYKit/Base/Foundation/NSDate+YYAdd.m | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/YYKit/Base/Foundation/NSDate+YYAdd.h b/YYKit/Base/Foundation/NSDate+YYAdd.h index d9ecb11d..54317d2b 100644 --- a/YYKit/Base/Foundation/NSDate+YYAdd.h +++ b/YYKit/Base/Foundation/NSDate+YYAdd.h @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSInteger minute; ///< Minute component (0~59) @property (nonatomic, readonly) NSInteger second; ///< Second component (0~59) @property (nonatomic, readonly) NSInteger nanosecond; ///< Nanosecond component +@property (nonatomic, readonly) NSInteger dayOfYear; ///< DayOfYear component (0~365/366) @property (nonatomic, readonly) NSInteger weekday; ///< Weekday component (1~7, first day is based on user setting) @property (nonatomic, readonly) NSInteger weekdayOrdinal; ///< WeekdayOrdinal component @property (nonatomic, readonly) NSInteger weekOfMonth; ///< WeekOfMonth component (1~5) diff --git a/YYKit/Base/Foundation/NSDate+YYAdd.m b/YYKit/Base/Foundation/NSDate+YYAdd.m index 3729088d..e071af35 100644 --- a/YYKit/Base/Foundation/NSDate+YYAdd.m +++ b/YYKit/Base/Foundation/NSDate+YYAdd.m @@ -46,6 +46,10 @@ - (NSInteger)nanosecond { return [[[NSCalendar currentCalendar] components:NSCalendarUnitSecond fromDate:self] nanosecond]; } +- (NSInteger)dayOfYear{ + return [[NSCalendar currentCalendar] ordinalityOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitYear forDate:self]; +} + - (NSInteger)weekday { return [[[NSCalendar currentCalendar] components:NSCalendarUnitWeekday fromDate:self] weekday]; }