@Test public void test_with() { Year base = Year.of(5); Year result = base.with(ChronoField.ERA, 0); assertEquals(result, base.with(IsoEra.of(0))); int prolepticYear = IsoChronology.INSTANCE.prolepticYear(IsoEra.of(0), 5); assertEquals(result.get(ChronoField.ERA), 0); assertEquals(result.get(ChronoField.YEAR), prolepticYear); assertEquals(result.get(ChronoField.YEAR_OF_ERA), 5); result = base.with(ChronoField.YEAR, 10); assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA)); assertEquals(result.get(ChronoField.YEAR), 10); assertEquals(result.get(ChronoField.YEAR_OF_ERA), 10); result = base.with(ChronoField.YEAR_OF_ERA, 20); assertEquals(result.get(ChronoField.ERA), base.get(ChronoField.ERA)); assertEquals(result.get(ChronoField.YEAR), 20); assertEquals(result.get(ChronoField.YEAR_OF_ERA), 20); }
@DataProvider(name = "era_epochSecond_dataProvider") Object[][] data_era_epochSecond() { return new Object[][] { {JapaneseChronology.INSTANCE, JapaneseEra.MEIJI, 1873 - YDIFF_MEIJI, 9, 7, 1, 2, 2, OFFSET_P0100}, {JapaneseChronology.INSTANCE, JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 2, 28, 1, 2, 2, OFFSET_M0100}, {JapaneseChronology.INSTANCE, JapaneseEra.HEISEI, 1989 - YDIFF_HEISEI, 1, 8, 1, 2, 2, OFFSET_P0100}, {HijrahChronology.INSTANCE, HijrahEra.AH, 1434, 9, 7, 1, 2, 2, OFFSET_P0100}, {MinguoChronology.INSTANCE, MinguoEra.BEFORE_ROC, 1873 - YDIFF_MINGUO, 9, 7, 1, 2, 2, OFFSET_P0100}, {MinguoChronology.INSTANCE, MinguoEra.ROC, 1928 - YDIFF_MINGUO, 2, 28, 1, 2, 2, OFFSET_M0100}, {MinguoChronology.INSTANCE, MinguoEra.ROC, 1989 - YDIFF_MINGUO, 1, 8, 1, 2, 2, OFFSET_P0100}, {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1873 + YDIFF_THAIBUDDHIST, 9, 7, 1, 2, 2, OFFSET_P0100}, {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1928 + YDIFF_THAIBUDDHIST, 2, 28, 1, 2, 2, OFFSET_M0100}, {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1989 + YDIFF_THAIBUDDHIST, 1, 8, 1, 2, 2, OFFSET_P0100}, {IsoChronology.INSTANCE, IsoEra.CE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100}, {IsoChronology.INSTANCE, IsoEra.CE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100}, {IsoChronology.INSTANCE, IsoEra.CE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100}, }; }
@DataProvider(name = "era_epochSecond_dataProvider") Object[][] data_era_epochSecond() { return new Object[][] { {IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_M0100}, {IsoEra.CE, 2008, 2, 28, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 2009, 3, 3, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 2009, 3, 3, 1, 2, 2, OFFSET_M0100}, {IsoEra.CE, 2009, 2, 28, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1968, 3, 3, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1968, 3, 3, 1, 2, 2, OFFSET_M0100}, {IsoEra.CE, 1968, 2, 28, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1969, 3, 3 , 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1969, 3, 3, 1, 2, 2, OFFSET_M0100}, {IsoEra.CE, 1969, 2, 28, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1970, 1, 1, 1, 2, 2, OFFSET_P0100}, {IsoEra.CE, 1970, 1, 1, 1, 2, 2, OFFSET_M0100}, {IsoEra.BCE, 5, 3, 3 , 1, 2, 2, OFFSET_P0100}, {IsoEra.BCE, 2, 3, 3 , 1, 2, 2, OFFSET_P0100}, }; }
/** * zGetStandardTextFieldDateString, This returns a string for the supplied date (or null), in * the standard format which could be used for displaying that date in the text field. */ private String zGetStandardTextFieldDateString(LocalDate date) { if (settings == null) { return ""; } String standardDateString = ""; if (date == null) { return standardDateString; } if (date.getEra() == IsoEra.CE) { standardDateString = date.format(settings.getFormatForDatesCommonEra()); } else { standardDateString = date.format(settings.getFormatForDatesBeforeCommonEra()); } return standardDateString; }
@Test public void test_date_withEra() { int year = 5; int month = 5; int dayOfMonth = 5; LocalDate test = IsoChronology.INSTANCE.date(IsoEra.BCE, year, month, dayOfMonth); assertEquals(test.getEra(), IsoEra.BCE); assertEquals(test.get(ChronoField.YEAR_OF_ERA), year); assertEquals(test.get(ChronoField.MONTH_OF_YEAR), month); assertEquals(test.get(ChronoField.DAY_OF_MONTH), dayOfMonth); assertEquals(test.get(YEAR), 1 + (-1 * year)); assertEquals(test.get(ERA), 0); assertEquals(test.get(YEAR_OF_ERA), year); }
@Test public void test_IsoChronology_dateYearDay() { Chronology chrono = Chronology.of("ISO"); ChronoLocalDate date1 = chrono.dateYearDay(IsoEra.CE, 5, 60); ChronoLocalDate date2 = chrono.date(IsoEra.CE, 5, 3, 1); assertEquals(date1, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60)); assertEquals(date2, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60)); }
@DataProvider(name = "IsoEras") Object[][] data_of_eras() { return new Object[][] { {IsoEra.BCE, "BCE", 0}, {IsoEra.CE, "CE", 1}, }; }
@DataProvider(name = "Eras") Era[][] data_of_calendars() { return new Era[][] { {HijrahEra.AH}, {IsoEra.BCE}, {IsoEra.CE}, {MinguoEra.BEFORE_ROC}, {MinguoEra.ROC}, {ThaiBuddhistEra.BEFORE_BE}, {ThaiBuddhistEra.BE}, }; }
@Test public void test_era_epochSecond_2() { assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 2008, 3, 3, 1, 2, 2, OFFSET_P0100), ZonedDateTime.of(2008, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond()); assertEquals(IsoChronology.INSTANCE.epochSecond(IsoEra.CE, 1969, 3, 3, 1, 2, 2, OFFSET_P0100), ZonedDateTime.of(1969, 3, 3, 1, 2, 2, 0, ZoneId.of("+01:00")).toEpochSecond()); }