I am looking for a simple but efficient Objective-C algorithm which, starting from a given quarter of a year (3 months), adds or subtracts a specific number of quarters.
For example, adding 10 quarters to Q1 of 2012, I get the year: 2012 + Floor(10 / 4) = 2012 + 2 = 2014, then the quarter: 1 + Mod (10, 4) = 1 + 2 = Q3. Subtracting 2 quarters from Q3 of 2011, I want to end up with Q1 of 2011.
What would be the most elegant code to accomplish this?
1 Answer