JulianDayConverter extends DateCalendarConverter { @Override public String convert(String inputDateStr) { if (StringUtils.isEmpty(inputDateStr)) { return inputDateStr; } String outputDateStr = inputDateStr; LocalDate localDate = super.parseStringToDate(inputDateStr); if (localDate == null) { return outputDateStr; } if (convertCalendarToTemporal) { outputDateStr = Long.toString(localDate.getLong(outputTemporalField)); } else { if (inputTemporalField != null && outputTemporalField != null) { outputDateStr = Long.toString(localDate.getLong(outputTemporalField)); } else { outputDateStr = formatDateToString(localDate); } } return outputDateStr; } JulianDayConverter(Chronology inputChronologyType, TemporalField outputTemporalField);  JulianDayConverter(Chronology inputChronologyType, String inputFormatPattern, Locale inputLocale,
            TemporalField outputTemporalField);  JulianDayConverter(TemporalField inputTemporalField, Chronology outputChronologyType);  JulianDayConverter(TemporalField inputTemporalField, Chronology outputChronologyType,
            String outputFormatPattern, Locale outputLocale);  JulianDayConverter(TemporalField inputTemporalField, TemporalField outputTemporalField); @Override String convert(String inputDateStr);  }
@Test public void testJulianToCalendar() { JulianDayConverter jc = new JulianDayConverter(JulianFields.JULIAN_DAY, IsoChronology.INSTANCE, null, Locale.US); assertEquals(calendarISO + ISOEarStr, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, JapaneseChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarJapa, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, HijrahChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarHijr, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, MinguoChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarMingGuo, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, ThaiBuddhistChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarThaiBudd, jc.convert(julianDay)); }
@Test public void testModifyJulianToCalendar() { JulianDayConverter jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, IsoChronology.INSTANCE, null, Locale.US); assertEquals(calendarISO + ISOEarStr, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, JapaneseChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarJapa, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, HijrahChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarHijr, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, MinguoChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarMingGuo, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, ThaiBuddhistChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarThaiBudd, jc.convert(modiJulianDay)); }
@Test public void testRataDieToCalendar() { JulianDayConverter jc = new JulianDayConverter(JulianFields.RATA_DIE, IsoChronology.INSTANCE, null, Locale.US); assertEquals(calendarISO + ISOEarStr, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, JapaneseChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarJapa, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, HijrahChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarHijr, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, MinguoChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarMingGuo, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, ThaiBuddhistChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarThaiBudd, jc.convert(rataDie)); }
@Test public void testEpchoToCalendar() { JulianDayConverter jc = new JulianDayConverter(ChronoField.EPOCH_DAY, IsoChronology.INSTANCE, null, Locale.US); assertEquals(calendarISO + ISOEarStr, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, JapaneseChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarJapa, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, HijrahChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarHijr, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, MinguoChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarMingGuo, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, ThaiBuddhistChronology.INSTANCE, outputPattern, outputLocale); assertEquals(calendarThaiBudd, jc.convert(epochDay)); }
@Test public void testCalendarISOToNumber() { JulianDayConverter jc = new JulianDayConverter(IsoChronology.INSTANCE, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(calendarISO)); jc = new JulianDayConverter(IsoChronology.INSTANCE, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(calendarISO)); jc = new JulianDayConverter(IsoChronology.INSTANCE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(calendarISO)); jc = new JulianDayConverter(IsoChronology.INSTANCE, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(calendarISO)); }
@Test public void testCalendarJapaToNumber() { JulianDayConverter jc = new JulianDayConverter(JapaneseChronology.INSTANCE, ChronoField.EPOCH_DAY); if (isReiwaEraSupported()) { assertEquals(epochDay_1, jc.convert(calendarJapa)); } else { assertEquals(epochDay, jc.convert(calendarJapa)); } jc = new JulianDayConverter(JapaneseChronology.INSTANCE, JulianFields.JULIAN_DAY); if (isReiwaEraSupported()) { assertEquals(julianDay_1, jc.convert(calendarJapa)); } else { assertEquals(julianDay, jc.convert(calendarJapa)); } jc = new JulianDayConverter(JapaneseChronology.INSTANCE, JulianFields.MODIFIED_JULIAN_DAY); if (isReiwaEraSupported()) { assertEquals(modiJulianDay_1, jc.convert(calendarJapa)); } else { assertEquals(modiJulianDay, jc.convert(calendarJapa)); } jc = new JulianDayConverter(JapaneseChronology.INSTANCE, JulianFields.RATA_DIE); if (isReiwaEraSupported()) { assertEquals(rataDie_1, jc.convert(calendarJapa)); } else { assertEquals(rataDie, jc.convert(calendarJapa)); } }
@Test public void testCalendarMingGuoToNumeber() { JulianDayConverter jc = new JulianDayConverter(MinguoChronology.INSTANCE, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(calendarMingGuo)); jc = new JulianDayConverter(MinguoChronology.INSTANCE, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(calendarMingGuo)); jc = new JulianDayConverter(MinguoChronology.INSTANCE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(calendarMingGuo)); jc = new JulianDayConverter(MinguoChronology.INSTANCE, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(calendarMingGuo)); }
@Test public void testCalendarHijrToNumeber() { JulianDayConverter jc = new JulianDayConverter(HijrahChronology.INSTANCE, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(calendarHijr)); jc = new JulianDayConverter(HijrahChronology.INSTANCE, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(calendarHijr)); jc = new JulianDayConverter(HijrahChronology.INSTANCE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(calendarHijr)); jc = new JulianDayConverter(HijrahChronology.INSTANCE, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(calendarHijr)); }
@Test public void testCalendarThaiBuddToNumber() { JulianDayConverter jc = new JulianDayConverter(ThaiBuddhistChronology.INSTANCE, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(calendarThaiBudd)); jc = new JulianDayConverter(ThaiBuddhistChronology.INSTANCE, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(calendarThaiBudd)); jc = new JulianDayConverter(ThaiBuddhistChronology.INSTANCE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(calendarThaiBudd)); jc = new JulianDayConverter(ThaiBuddhistChronology.INSTANCE, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(calendarThaiBudd)); }
@Test public void testJulianToOtherNumbers() { JulianDayConverter jc = new JulianDayConverter(JulianFields.JULIAN_DAY, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.JULIAN_DAY, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(julianDay)); }
@Test public void testModifyJulianToOtherNumbers() { JulianDayConverter jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(modiJulianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(modiJulianDay)); }
@Test public void testRataDieToOtherNumbers() { JulianDayConverter jc = new JulianDayConverter(JulianFields.RATA_DIE, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(rataDie)); jc = new JulianDayConverter(JulianFields.RATA_DIE, ChronoField.EPOCH_DAY); assertEquals(epochDay, jc.convert(rataDie)); }
@Test public void testEpochToOtherNumbers() { JulianDayConverter jc = new JulianDayConverter(ChronoField.EPOCH_DAY, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert(epochDay)); jc = new JulianDayConverter(ChronoField.EPOCH_DAY, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert(epochDay)); }
@Test public void testInvalidConvert() { JulianDayConverter jc = new JulianDayConverter(JulianFields.JULIAN_DAY, IsoChronology.INSTANCE); assertEquals(null, jc.convert(null)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, IsoChronology.INSTANCE); assertEquals("", jc.convert("")); jc = new JulianDayConverter(IsoChronology.INSTANCE, JulianFields.JULIAN_DAY); jc = new JulianDayConverter(IsoChronology.INSTANCE, "yyyy/MM/dd", Locale.UK, JulianFields.JULIAN_DAY); assertEquals(calendarISO, jc.convert(calendarISO)); jc = new JulianDayConverter(JapaneseChronology.INSTANCE, "dd/MM/yyyy", Locale.US, JulianFields.JULIAN_DAY); assertEquals(calendarJapa, jc.convert(calendarJapa)); jc = new JulianDayConverter(IsoChronology.INSTANCE, null); assertEquals("abc", jc.convert("abc")); }
@Test public void testCalendarToNumberWithInputMonthLabel() { JulianDayConverter jc = new JulianDayConverter(IsoChronology.INSTANCE, "dd-LLL-yyyy", Locale.UK, JulianFields.JULIAN_DAY); assertEquals(julianDay, jc.convert("18-May-2017")); jc = new JulianDayConverter(IsoChronology.INSTANCE, "yyyy-LLL-dd", Locale.CHINESE, JulianFields.MODIFIED_JULIAN_DAY); assertEquals(modiJulianDay, jc.convert("2017-五月-18")); jc = new JulianDayConverter(IsoChronology.INSTANCE, "dd-LLL-yyyy HH:mm:ss", Locale.UK, JulianFields.RATA_DIE); assertEquals(rataDie, jc.convert("18-May-2017 02:03:04")); }
@Test public void testNumberToCalendarWithOutputPattern() { JulianDayConverter jc = new JulianDayConverter(JulianFields.JULIAN_DAY, IsoChronology.INSTANCE, "dd/MM/yyyy", Locale.UK); assertEquals("18/05/2017", jc.convert(julianDay)); jc = new JulianDayConverter(JulianFields.MODIFIED_JULIAN_DAY, IsoChronology.INSTANCE, "dd/LLL/yyyy", Locale.CHINESE); final String convertedJulianDate = jc.convert(modiJulianDay); assertTrue("18/五月/2017".equals(convertedJulianDate) || "18/5月/2017".equals(convertedJulianDate)); jc = new JulianDayConverter(JapaneseChronology.INSTANCE, null, Locale.US, JulianFields.MODIFIED_JULIAN_DAY); if (isReiwaEraSupported()) { assertEquals(modiJulianDay_1, jc.convert(calendarJapa)); } else { assertEquals(modiJulianDay, jc.convert(calendarJapa)); } }