I want to be able to round any given moment to the nearest period to support data grouping.
i.e. someone may want to group for 2 weeks, so Instant, I want to be able to work in the near future (before or after) at the border of the period where βnowβ is considered the end of the current period. If today is Tuesday, then think that this 2 week ends this week. Given any date (now back), I would like to calculate the β2-week periodβ in which it fits.
// pseudo code Period sevenDays = Days.SEVEN; Instant nearestWeek = sevenDays.roundToNearest(new DateTime()); Period twelveHours = Hours.hours(12); Instant nearestHalfDay = twelveHours.roundToNearest(new DateTime());
I hope this makes sense, any help or pointers are much appreciated.
Jonas klemming
source share