Skip to content

Commit

Permalink
use _Pragma to ignore deprecated warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakey committed Dec 4, 2016
1 parent 0810ada commit 9769b7d
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions JKCategories/Foundation/NSDate/NSDate+JKUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
if ([UIDevice currentDevice].systemVersion.floatValue > 8.0f){ \
components = (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit); \
}else{ \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
components = (NSYearCalendarUnit| NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekdayOrdinalCalendarUnit); \
_Pragma("clang diagnostic pop") \
} \
components; \
})\
Expand All @@ -38,7 +41,6 @@

#endif


@implementation NSDate (Utilities)

// Courtesy of Lukasz Margielewski
Expand Down Expand Up @@ -170,13 +172,8 @@ - (NSString *) jk_longDateString

- (BOOL) jk_isEqualToDateIgnoringTime: (NSDate *) aDate
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components1 = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
NSDateComponents *components2 = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:aDate];
#pragma clang diagnostic pop


return ((components1.year == components2.year) &&
(components1.month == components2.month) &&
(components1.day == components2.day));
Expand All @@ -200,8 +197,6 @@ - (BOOL) jk_isYesterday
// This hard codes the assumption that a week is 7 days
- (BOOL) jk_isSameWeekAsDate: (NSDate *) aDate
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components1 = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
NSDateComponents *components2 = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:aDate];

Expand All @@ -210,7 +205,6 @@ - (BOOL) jk_isSameWeekAsDate: (NSDate *) aDate

// Must have a time interval under 1 week. Thanks @aclark
return (abs([self timeIntervalSinceDate:aDate]) < JK_D_WEEK);
#pragma clang diagnostic pop

}

Expand Down Expand Up @@ -467,21 +461,15 @@ - (NSDate *) jk_dateBySubtractingMinutes: (NSInteger) dMinutes

- (NSDateComponents *) jk_componentsWithOffsetFromDate: (NSDate *) aDate
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *dTime = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:aDate toDate:self options:0];
#pragma clang diagnostic pop
return dTime;
}

#pragma mark - Extremes

- (NSDate *) jk_dateAtStartOfDay
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
components.hour = 0;
components.minute = 0;
components.second = 0;
Expand All @@ -491,10 +479,7 @@ - (NSDate *) jk_dateAtStartOfDay
// Thanks gsempe & mteece
- (NSDate *) jk_dateAtEndOfDay
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop

components.hour = 23; // Thanks Aleksey Kononov
components.minute = 59;
Expand Down Expand Up @@ -615,82 +600,55 @@ - (NSInteger)jk_nearestHour
}
- (NSInteger) jk_hour
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.hour;
}

- (NSInteger) jk_minute
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.minute;
}

- (NSInteger) jk_seconds
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.second;
}

- (NSInteger) jk_day
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.day;
}

- (NSInteger) jk_month
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.month;
}

- (NSInteger) jk_week
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.weekOfMonth;
}

- (NSInteger) jk_weekday
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.weekday;
}

- (NSInteger) jk_nthWeekday // e.g. 2nd Tuesday of the month is 2
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.weekdayOrdinal;
}

- (NSInteger) jk_year
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSDateComponents *components = [[NSDate jk_currentCalendar] components:JK_NSDATE_UTILITIES_COMPONENT_FLAGS fromDate:self];
#pragma clang diagnostic pop
return components.year;
}
@end

0 comments on commit 9769b7d

Please sign in to comment.