When you choose dayOfMonth, you are asking to round to the nearest day, where as with minuteOfHour you are asking to round to the nearest minute. The rounding occurs relative to the offset.
The millis value for the date is simply a reflection of the offset. The rounding applies to the local date time, which is why both the +01:00 and UTC offsets print a time of midnight. Stephen On 22 December 2011 21:13, Shay Banon <kim...@gmail.com> wrote: > Heya, > > I got this strange behavior with rounding and timezone. Depending on the > type of rounding (dayOfMonth vs. minuteOfHour) I am getting different > results for the same rounded value. The following code runs with dayOfMonth: > > MutableDateTime time = new MutableDateTime(DateTimeZone.UTC); > time.setZone(DateTimeZone.forOffsetHours(1)); > time.setRounding(time.getChronology().dayOfMonth(), > MutableDateTime.ROUND_FLOOR); > > MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC); > utcTime.setRounding(utcTime.getChronology().dayOfMonth(), > MutableDateTime.ROUND_FLOOR); > > time.setMillis(0); > utcTime.setMillis(0); > System.out.println("time: " + time + ", utc " + utcTime); > System.out.println("time_millis: " + time.getMillis() + ", > utc_millis " + utcTime.getMillis()); > > And the output shows that the time millis differ between the utc one, and > the time zone one. On the other hand, just changing to round based on > minuteOfHour, results in the millis between the two to be the same: > > MutableDateTime time = new MutableDateTime(DateTimeZone.UTC); > time.setZone(DateTimeZone.forOffsetHours(1)); > time.setRounding(time.getChronology().minuteOfHour(), > MutableDateTime.ROUND_FLOOR); > > MutableDateTime utcTime = new MutableDateTime(DateTimeZone.UTC); > utcTime.setRounding(utcTime.getChronology().minuteOfHour(), > MutableDateTime.ROUND_FLOOR); > > time.setMillis(0); > utcTime.setMillis(0); > System.out.println("time: " + time + ", utc " + utcTime); > System.out.println("time_millis: " + time.getMillis() + ", > utc_millis " + utcTime.getMillis()); > > > I must be missing something obvious, but I don't understand why the results > would be different between the two runs? The results of the two runs should > be the same (and I think they all should have 0 as millis, no?). > > -shay.banon > > ------------------------------------------------------------------------------ > Write once. Port to many. > Get the SDK and tools to simplify cross-platform app development. Create > new or port existing apps to sell to consumers worldwide. Explore the > Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join > http://p.sf.net/sfu/intel-appdev > _______________________________________________ > Joda-interest mailing list > Joda-interest@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/joda-interest > ------------------------------------------------------------------------------ Write once. Port to many. Get the SDK and tools to simplify cross-platform app development. Create new or port existing apps to sell to consumers worldwide. Explore the Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join http://p.sf.net/sfu/intel-appdev _______________________________________________ Joda-interest mailing list Joda-interest@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/joda-interest