Skip to content

Instantly share code, notes, and snippets.

@stefanluptak
Created February 1, 2011 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanluptak/805853 to your computer and use it in GitHub Desktop.
Save stefanluptak/805853 to your computer and use it in GitHub Desktop.
Cocoa vs. Rails method returning the end of current month
- (NSDate *)endOfThisMonth {
NSDate *endOfMonth = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *comp = [calendar components:(NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]];
[comp setMonth:[comp month]+1];
[comp setDay:1];
endOfMonth = [calendar dateFromComponents:comp];
return [endOfMonth dateByAddingTimeInterval:-(60*60*24)];
}
def end_of_this_month
Time.now.end_of_month
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment