Commits

Ryan Wilcox committed dc33c9a

added date utils

  • Participants
  • Parent commits 4502dc9

Comments (0)

Files changed (2)

File Date_Utils.h

+//
+//  Date_Utilities.h
+//
+//  Created by Ryan Wilcox on 4/18/2012.
+//  Copyright 2012 Wilcox Development Solutions. Licensed under the BSD open source license, 2012
+//  See <http://bitbucket.org/rwilcox/cocoa_utils/>
+//
+
+NSDate* getDateDaysFromNow(int daysToAdd, int hours, int minutes);

File Date_Utils.m

+//
+//  Date_Utilities.h
+//
+//  Created by Ryan Wilcox on 4/18/2012.
+//  Copyright 2012 Wilcox Development Solutions. Licensed under the BSD open source license, 2012
+//  See <http://bitbucket.org/rwilcox/cocoa_utils/>
+//
+
+NSDate* getDateDaysFromNow(int daysToAdd, int hours, int minutes)
+{
+    NSDate *now = [NSDate date];
+    // create a calendar
+    NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
+
+    NSDateComponents *components = [gregorian components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:now];
+
+    //NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
+    [components setDay: components.day + daysToAdd];
+    [components setHour: hours];
+    [components setMinute: minutes];
+
+    NSDate *newDate2 = [gregorian dateFromComponents: components];
+    return newDate2;
+}