Created
February 1, 2011 13:32
-
-
Save stefanluptak/805853 to your computer and use it in GitHub Desktop.
Cocoa vs. Rails method returning the end of current month
This file contains 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 *)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)]; | |
} |
This file contains 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
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