Skip to content

Instantly share code, notes, and snippets.

@4PixelsDev
Created February 23, 2014 12:33
Show Gist options
  • Save 4PixelsDev/9170795 to your computer and use it in GitHub Desktop.
Save 4PixelsDev/9170795 to your computer and use it in GitHub Desktop.
IOS: NSDateComponents extension with methods to determine whether current Year
//
// NSDateComponents+Extended.h
// FBBirthdays
//
// Created by Igor on 2/23/14.
// Copyright (c) 2014 4Pixels. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDateComponents (Extended)
/**
* Returns YES if year property is leap year, NO otherwise.
*
* @return YES if year property is leap year, NO otherwise.
*/
- (BOOL) isLeapYear;
/**
* Returns YES if passed year is leap year, NO otherwise.
*
* @param year the number of year which should determine is it leap or not.
*
* @return YES if passed year is leap year, NO otherwise.
*/
- (BOOL) isLeapYear:(NSInteger)year;
@end
//
// NSDateComponents+Extended.m
// FBBirthdays
//
// Created by Igor on 2/23/14.
// Copyright (c) 2014 4Pixels. All rights reserved.
//
#import "NSDateComponents+Extended.h"
@implementation NSDateComponents (Extended)
- (BOOL) isLeapYear
{
return ((self.year % 4 == 0) && (self.year % 100 != 0)) || (self.year % 400 == 0);
}
- (BOOL) isLeapYear:(NSInteger)year
{
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment