Date Ranges is an NSDate category to help get start and end dates of a date unit such as day, week, month or year. So, [[NSDate date] startOfDay]
that returns an NSDate at the start of the current day. [[NSDate date] endOfDay]
will return a date at the end of today.
Ever need to create a CoreData predicate that searches for something within a range, like yesterday, tomorrow or next week? Now just use this category.
Get the Previous, Current or Next
- day
- week
- month
- year
Along with any offset for days, weeks, months and years. So given the date 29 April 1901 I can use the following methods
[date endOfDayWithOffset:10000]
to get then end of the 10000th day after 29 April 1901.
Alternatively I could use [date endOfYearWithOffset:50]
to get a date and time at the end of 1951.
This is a command line utility for running a few examples, clone the project and copy NSDate+dateRange.h
and NSDate+dateRange.m
into your project. These are ARC files, so if you're not using ARC, it's probably best to fork it and do your own memory management.