@Test( groups = {"tck"}, expectedExceptions = DateTimeException.class) public void test_adjust_toMonth() { JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4); jdate.with(Month.APRIL); }
private void testChronology() { out.printf("--------------------- Test Chronology ---------------------------\n"); birthDays .entrySet() .forEach( e -> { JapaneseDate japaneseDate = JapaneseDate.from(stringToTime(e.getValue())); out.printf("%s was born %s.\n", e.getKey(), japaneseDate); }); }
private static void useLocalDate() { LocalDate date = LocalDate.of(2014, 3, 18); int year = date.getYear(); // 2014 Month month = date.getMonth(); // MARCH int day = date.getDayOfMonth(); // 18 DayOfWeek dow = date.getDayOfWeek(); // TUESDAY int len = date.lengthOfMonth(); // 31 (days in March) boolean leap = date.isLeapYear(); // false (not a leap year) System.out.println(date); int y = date.get(ChronoField.YEAR); int m = date.get(ChronoField.MONTH_OF_YEAR); int d = date.get(ChronoField.DAY_OF_MONTH); LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20 int hour = time.getHour(); // 13 int minute = time.getMinute(); // 45 int second = time.getSecond(); // 20 System.out.println(time); LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45 LocalDateTime dt2 = LocalDateTime.of(date, time); LocalDateTime dt3 = date.atTime(13, 45, 20); LocalDateTime dt4 = date.atTime(time); LocalDateTime dt5 = time.atDate(date); System.out.println(dt1); LocalDate date1 = dt1.toLocalDate(); System.out.println(date1); LocalTime time1 = dt1.toLocalTime(); System.out.println(time1); Instant instant = Instant.ofEpochSecond(44 * 365 * 86400); Instant now = Instant.now(); Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time); Duration d2 = Duration.between(instant, now); System.out.println(d1.getSeconds()); System.out.println(d2.getSeconds()); Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES); System.out.println(threeMinutes); JapaneseDate japaneseDate = JapaneseDate.from(date); System.out.println(japaneseDate); }
@Test( dataProvider = "toString", groups = {"tck"}) public void test_toString(JapaneseDate jdate, String expected) { assertEquals(jdate.toString(), expected); }
// ----------------------------------------------------------------------- // JapaneseDate.with(Local*) // ----------------------------------------------------------------------- @Test(groups = {"tck"}) public void test_adjust_toLocalDate() { JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1726, 1, 4); JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6)); assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6)); }
@Test(groups = {"tck"}) public void test_adjust2() { JapaneseDate base = JapaneseChronology.INSTANCE.date(1728, 12, 2); JapaneseDate test = base.with(Adjusters.lastDayOfMonth()); assertEquals(test, JapaneseChronology.INSTANCE.date(1728, 12, 31)); }