I need to fetch objects from core data within specific time periods; i.e. weekly, monthly, yearly.
I would then feed the dates generated from the components into a predicate like this:
[NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@",
intervalStartDate, intervalEndDate];
Examples of intervals/periods:
start end start end
weekly Jan 2, 2012 to Jan 08, 2012, Jan 9, 2012 to Jan 15, 2012, etc.
monthly Jan 1, 2012 to Jan 31, 2012, Feb 1, 2012 to Feb 29, 2012, etc.
yearly Jan 1, 2011 to Dec 31, 2011, Jan 1, 2012 to Dec 31, 2012, etc.
With these, I could get the specific objects during that time period.
My problem is, that I don’t know what would be the best way to increment the date components. I have to account for leap years, etc.
What would be the best way to achieve this?
As long as you use the correct NSCalendar and as long as you treat each calculation of dates independent of each other, the resulting dates should be fine.