From 7153eb4ff1e15cab640e9b1f7a9007e0501f9318 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Sat, 13 Jun 2020 16:10:54 -0400 Subject: [PATCH] Drop time component getters in favor of just using the getters on the LocalTime component. --- src/main/java/org/threeten/extra/DayTime.java | 44 ++----------------- .../java/org/threeten/extra/DayTimeTest.java | 43 +++++------------- 2 files changed, 14 insertions(+), 73 deletions(-) diff --git a/src/main/java/org/threeten/extra/DayTime.java b/src/main/java/org/threeten/extra/DayTime.java index a1e479ca..7e7ead97 100644 --- a/src/main/java/org/threeten/extra/DayTime.java +++ b/src/main/java/org/threeten/extra/DayTime.java @@ -33,6 +33,7 @@ import java.io.Serializable; import java.time.DayOfWeek; +import java.time.LocalDate; import java.time.LocalTime; import java.time.temporal.*; import java.util.Objects; @@ -122,49 +123,10 @@ public DayOfWeek getDayOfWeek() { } /** - * Gets the hour-of-day field. + * Gets the {@code LocalTime} part of this day-time. * - * @return the hour of the day, from 0 to 23 - * - * @see LocalTime#getHour() + * @return the time part of this day-time, not null */ - public int getHour() { - return localTime.getHour(); - } - - /** - * Gets the minute-of-hour field. - * - * @return the minute of the hour, from 0 to 59 - * - * @see LocalTime#getMinute() - */ - public int getMinute() { - return localTime.getMinute(); - } - - /** - * Returns the second-of-minute field. - * - * @return the second of the minute, from 0 to 59 - * - * @see LocalTime#getSecond() - */ - public int getSecond() { - return localTime.getSecond(); - } - - /** - * Returns the nano-of-second field. - * - * @return the nano-of-second, from 0 to 999,999,999 - * - * @see LocalTime#getNano() - */ - public int getNano() { - return localTime.getNano(); - } - public LocalTime toLocalTime() { return localTime; } diff --git a/src/test/java/org/threeten/extra/DayTimeTest.java b/src/test/java/org/threeten/extra/DayTimeTest.java index 1b3d8a1d..9cc97402 100644 --- a/src/test/java/org/threeten/extra/DayTimeTest.java +++ b/src/test/java/org/threeten/extra/DayTimeTest.java @@ -33,7 +33,6 @@ import org.junit.Before; import org.junit.Test; -import org.threeten.extra.DayTime; import java.time.*; import java.time.temporal.ChronoField; @@ -63,34 +62,14 @@ public void testGetDayOfWeek() { assertEquals(DAY_OF_WEEK, dayTime.getDayOfWeek()); } - @Test - public void testGetHour() { - assertEquals(LOCAL_TIME.getHour(), dayTime.getHour()); - } - - @Test - public void testGetMinute() { - assertEquals(LOCAL_TIME.getMinute(), dayTime.getMinute()); - } - - @Test - public void testGetSecond() { - assertEquals(LOCAL_TIME.getSecond(), dayTime.getSecond()); - } - - @Test - public void testGetNano() { - assertEquals(LOCAL_TIME.getNano(), dayTime.getNano()); - } - @Test public void testFrom() { final DayTime dayTime = DayTime.from(LocalDateTime.parse("2017-11-17T10:15:30")); assertEquals(DayOfWeek.FRIDAY, dayTime.getDayOfWeek()); - assertEquals(10, dayTime.getHour()); - assertEquals(15, dayTime.getMinute()); - assertEquals(30, dayTime.getSecond()); + assertEquals(10, dayTime.toLocalTime().getHour()); + assertEquals(15, dayTime.toLocalTime().getMinute()); + assertEquals(30, dayTime.toLocalTime().getSecond()); } @Test @@ -114,12 +93,12 @@ public void testPlusTemporalUnit() { final DayTime lateMondayEvening = DayTime.of(DayOfWeek.MONDAY, LocalTime.of(23, 0)); assertEquals(DayOfWeek.WEDNESDAY, earlyTuesdayMorning.plus(1, ChronoUnit.DAYS).getDayOfWeek()); - assertEquals(1, earlyTuesdayMorning.plus(1, ChronoUnit.DAYS).getHour()); - assertEquals(0, earlyTuesdayMorning.plus(1, ChronoUnit.DAYS).getMinute()); + assertEquals(1, earlyTuesdayMorning.plus(1, ChronoUnit.DAYS).toLocalTime().getHour()); + assertEquals(0, earlyTuesdayMorning.plus(1, ChronoUnit.DAYS).toLocalTime().getMinute()); assertEquals(DayOfWeek.TUESDAY, earlyTuesdayMorning.plus(77, ChronoUnit.MINUTES).getDayOfWeek()); - assertEquals(2, earlyTuesdayMorning.plus(77, ChronoUnit.MINUTES).getHour()); - assertEquals(17, earlyTuesdayMorning.plus(77, ChronoUnit.MINUTES).getMinute()); + assertEquals(2, earlyTuesdayMorning.plus(77, ChronoUnit.MINUTES).toLocalTime().getHour()); + assertEquals(17, earlyTuesdayMorning.plus(77, ChronoUnit.MINUTES).toLocalTime().getMinute()); assertEquals(DayOfWeek.TUESDAY, lateMondayEvening.plus(97, ChronoUnit.MINUTES).getDayOfWeek()); } @@ -129,12 +108,12 @@ public void testMinus() { final DayTime earlyTuesdayMorning = DayTime.of(DayOfWeek.TUESDAY, LocalTime.of(1, 0)); assertEquals(DayOfWeek.MONDAY, earlyTuesdayMorning.minus(1, ChronoUnit.DAYS).getDayOfWeek()); - assertEquals(1, earlyTuesdayMorning.minus(1, ChronoUnit.DAYS).getHour()); - assertEquals(0, earlyTuesdayMorning.minus(1, ChronoUnit.DAYS).getMinute()); + assertEquals(1, earlyTuesdayMorning.minus(1, ChronoUnit.DAYS).toLocalTime().getHour()); + assertEquals(0, earlyTuesdayMorning.minus(1, ChronoUnit.DAYS).toLocalTime().getMinute()); assertEquals(DayOfWeek.MONDAY, earlyTuesdayMorning.minus(77, ChronoUnit.MINUTES).getDayOfWeek()); - assertEquals(23, earlyTuesdayMorning.minus(77, ChronoUnit.MINUTES).getHour()); - assertEquals(43, earlyTuesdayMorning.minus(77, ChronoUnit.MINUTES).getMinute()); + assertEquals(23, earlyTuesdayMorning.minus(77, ChronoUnit.MINUTES).toLocalTime().getHour()); + assertEquals(43, earlyTuesdayMorning.minus(77, ChronoUnit.MINUTES).toLocalTime().getMinute()); } @Test(expected = UnsupportedTemporalTypeException.class)