DateTimeUtils { public static Date cfiDateToUtc(int days, long seconds, long microseconds) { final Calendar calendar = getUtcCalendar(); calendar.set(Calendar.YEAR, 2000); calendar.set(Calendar.MONTH, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.DATE, days); calendar.add(Calendar.SECOND, (int) seconds); calendar.add(Calendar.MILLISECOND, (int) (microseconds * 0.001)); return calendar.getTime(); }  static Calendar getUtcCalendar(); static Date cfiDateToUtc(int days, long seconds, long microseconds); static Date cfiDateToUtc(CompoundData compoundData); static Date mjdFloatDateToUtc(float mjd); static String toVariableHeaderFormat(Date date); static String toFixedHeaderFormat(Date date); static Date fromFixedHeaderFormat(String dateString); static String toFileNameFormat(Date date);  }
@Test public void testCfiDateToUtc() { Date date = DateTimeUtils.cfiDateToUtc(0, 0, 0); assertEquals("Sat Jan 01 01:00:00 CET 2000", date.toString()); date = DateTimeUtils.cfiDateToUtc(1, 0, 0); assertEquals("Sun Jan 02 01:00:00 CET 2000", date.toString()); date = DateTimeUtils.cfiDateToUtc(1, 10, 0); long timeWithoutMillis = date.getTime(); assertEquals("Sun Jan 02 01:00:10 CET 2000", date.toString()); date = DateTimeUtils.cfiDateToUtc(1, 10, 100000); assertEquals("Sun Jan 02 01:00:10 CET 2000", date.toString()); assertEquals(timeWithoutMillis + 100, date.getTime()); }
@Test public void testCfiDateToUtc_formCompound() throws IOException { final CompoundData compoundData = mock(CompoundData.class); when(compoundData.getInt("Days")).thenReturn(187); when(compoundData.getUInt("Seconds")).thenReturn(78765L); when(compoundData.getUInt("Microseconds")).thenReturn(1007L); Date date = DateTimeUtils.cfiDateToUtc(compoundData); assertEquals("Thu Jul 06 23:52:45 CEST 2000", date.toString()); when(compoundData.getInt("Days")).thenReturn(0); when(compoundData.getUInt("Seconds")).thenReturn(0L); when(compoundData.getUInt("Microseconds")).thenReturn(0L); date = DateTimeUtils.cfiDateToUtc(compoundData); assertEquals("Sat Jan 01 01:00:00 CET 2000", date.toString()); }