Created
December 23, 2010 01:19
-
-
Save gavingmiller/752403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Surrounding.h | |
// | |
// Created by Josh Kendall on 12/22/10. | |
// Copyright 2010 JoshuaKendall.com. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSDate (Surrounding) | |
- (NSDate *)dateSinceToday:(int)days; | |
- (NSDate *)yesterday; | |
- (NSDate *)tomorrow; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Surrounding.m | |
// | |
// Created by Josh Kendall on 12/22/10. | |
// Copyright 2010 JoshuaKendall.com. All rights reserved. | |
// | |
#import "NSDate+Surrounding.h" | |
@implementation NSDate (Surrounding) | |
- (NSDate *)dateSinceToday:(int)days { | |
NSDate *date = [NSDate date]; | |
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease]; | |
[components setDay:days]; | |
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; | |
return [gregorian dateByAddingComponents:components toDate:date options:0]; | |
} | |
- (NSDate *)yesterday { | |
return [self dateSinceToday: -1]; | |
} | |
- (NSDate *)tomorrow { | |
return [self dateSinceToday: 1]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment