iZettle/izettle-toolbox — pull request #59 by adamvoncorswant (2014-03-05 00:31:11+00:00)
Title: CalendarTruncator: Add forwardInstant utility method

The need to easily forward or revert an instant a specific field is
prevalent in a lot of code. One could argue that the platform default
methods on the Calendar object would suffice, but it turns out that a
lot of times, all that is available is a Date object, not a calendar.
This is especially true when other methods in CalendarTruncator has been
used.

With this method, a lot of places that looks something like:
```java
Calendar calendar = CalendarCreator.create(timeZoneId);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR, 0);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
calendar.add(Calendar.WEEK_OF_YEAR, -span);
Date fiveWeeksAgo = startCal.getTime();
```
could be replaced with:
```java
Date now = new Date();
Date startOfThisWeek = truncateInstant(timeZoneId, CalendarField.WEEK, now);
Date fiveWeeksAgo = forwardInstant(timeZoneId, CalendarField.WEEK, startOfThisWeek, -5);
```

ping @xiaodong-izettle or @oskarwiksten