@Test public void round1() { GregorianCalendar cal = new GregorianCalendar(2013, 3, 14, 14, 23, 15); cal.set(GregorianCalendar.MILLISECOND, 123); Date date = cal.getTime(); TimeScales.round(cal, GregorianCalendar.MILLISECOND); assertThat(cal.getTime(), equalTo(date)); TimeScales.round(cal, GregorianCalendar.SECOND); assertThat(cal, equalTo(new GregorianCalendar(2013, 3, 14, 14, 23, 15))); TimeScales.round(cal, GregorianCalendar.MINUTE); assertThat(cal, equalTo(new GregorianCalendar(2013, 3, 14, 14, 23, 0))); }
static void round(GregorianCalendar cal, int field) { if (GregorianCalendar.MILLISECOND == field) { return; } cal.set(GregorianCalendar.MILLISECOND, 0); if (GregorianCalendar.SECOND == field) { return; } cal.set(GregorianCalendar.SECOND, 0); if (GregorianCalendar.MINUTE == field) { return; } cal.set(GregorianCalendar.MINUTE, 0); if ( HOUR_FIELD_ID == field ) { return; } cal.set( HOUR_FIELD_ID , FIRST_HOUR ); if ( DAY_FIELD_ID == field ) { return; } cal.set(DAY_FIELD_ID , FIRST_DAY ); if ( WEEK_FIELD_ID == field ) { return; } cal.set( GregorianCalendar.DAY_OF_MONTH , 1 ); if ( GregorianCalendar.MONTH == field ) { return; } cal.set( GregorianCalendar.MONTH , 0 ); if ( GregorianCalendar.YEAR == field ) { return; } cal.set( GregorianCalendar.YEAR , 0 ); }
TimeScales { static void round(GregorianCalendar cal, int field) { if (GregorianCalendar.MILLISECOND == field) { return; } cal.set(GregorianCalendar.MILLISECOND, 0); if (GregorianCalendar.SECOND == field) { return; } cal.set(GregorianCalendar.SECOND, 0); if (GregorianCalendar.MINUTE == field) { return; } cal.set(GregorianCalendar.MINUTE, 0); if ( HOUR_FIELD_ID == field ) { return; } cal.set( HOUR_FIELD_ID , FIRST_HOUR ); if ( DAY_FIELD_ID == field ) { return; } cal.set(DAY_FIELD_ID , FIRST_DAY ); if ( WEEK_FIELD_ID == field ) { return; } cal.set( GregorianCalendar.DAY_OF_MONTH , 1 ); if ( GregorianCalendar.MONTH == field ) { return; } cal.set( GregorianCalendar.MONTH , 0 ); if ( GregorianCalendar.YEAR == field ) { return; } cal.set( GregorianCalendar.YEAR , 0 ); } }
TimeScales { static void round(GregorianCalendar cal, int field) { if (GregorianCalendar.MILLISECOND == field) { return; } cal.set(GregorianCalendar.MILLISECOND, 0); if (GregorianCalendar.SECOND == field) { return; } cal.set(GregorianCalendar.SECOND, 0); if (GregorianCalendar.MINUTE == field) { return; } cal.set(GregorianCalendar.MINUTE, 0); if ( HOUR_FIELD_ID == field ) { return; } cal.set( HOUR_FIELD_ID , FIRST_HOUR ); if ( DAY_FIELD_ID == field ) { return; } cal.set(DAY_FIELD_ID , FIRST_DAY ); if ( WEEK_FIELD_ID == field ) { return; } cal.set( GregorianCalendar.DAY_OF_MONTH , 1 ); if ( GregorianCalendar.MONTH == field ) { return; } cal.set( GregorianCalendar.MONTH , 0 ); if ( GregorianCalendar.YEAR == field ) { return; } cal.set( GregorianCalendar.YEAR , 0 ); }  }
TimeScales { static void round(GregorianCalendar cal, int field) { if (GregorianCalendar.MILLISECOND == field) { return; } cal.set(GregorianCalendar.MILLISECOND, 0); if (GregorianCalendar.SECOND == field) { return; } cal.set(GregorianCalendar.SECOND, 0); if (GregorianCalendar.MINUTE == field) { return; } cal.set(GregorianCalendar.MINUTE, 0); if ( HOUR_FIELD_ID == field ) { return; } cal.set( HOUR_FIELD_ID , FIRST_HOUR ); if ( DAY_FIELD_ID == field ) { return; } cal.set(DAY_FIELD_ID , FIRST_DAY ); if ( WEEK_FIELD_ID == field ) { return; } cal.set( GregorianCalendar.DAY_OF_MONTH , 1 ); if ( GregorianCalendar.MONTH == field ) { return; } cal.set( GregorianCalendar.MONTH , 0 ); if ( GregorianCalendar.YEAR == field ) { return; } cal.set( GregorianCalendar.YEAR , 0 ); }  static TimeScale linearAbsoluteScale(); }
TimeScales { static void round(GregorianCalendar cal, int field) { if (GregorianCalendar.MILLISECOND == field) { return; } cal.set(GregorianCalendar.MILLISECOND, 0); if (GregorianCalendar.SECOND == field) { return; } cal.set(GregorianCalendar.SECOND, 0); if (GregorianCalendar.MINUTE == field) { return; } cal.set(GregorianCalendar.MINUTE, 0); if ( HOUR_FIELD_ID == field ) { return; } cal.set( HOUR_FIELD_ID , FIRST_HOUR ); if ( DAY_FIELD_ID == field ) { return; } cal.set(DAY_FIELD_ID , FIRST_DAY ); if ( WEEK_FIELD_ID == field ) { return; } cal.set( GregorianCalendar.DAY_OF_MONTH , 1 ); if ( GregorianCalendar.MONTH == field ) { return; } cal.set( GregorianCalendar.MONTH , 0 ); if ( GregorianCalendar.YEAR == field ) { return; } cal.set( GregorianCalendar.YEAR , 0 ); }  static TimeScale linearAbsoluteScale(); final static int HOUR_FIELD_ID; final static int FIRST_HOUR; final static int DAY_FIELD_ID; final static int FIRST_DAY; final static int WEEK_FIELD_ID; final static int FIRST_WEEK; }