Skip to content

Commit

Permalink
Drop time component getters in favor of just using the getters on the…
Browse files Browse the repository at this point in the history
… LocalTime component.
  • Loading branch information
jchambers committed Jun 13, 2020
1 parent 7f3bf85 commit 7153eb4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 73 deletions.
44 changes: 3 additions & 41 deletions src/main/java/org/threeten/extra/DayTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
43 changes: 11 additions & 32 deletions src/test/java/org/threeten/extra/DayTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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());
}
Expand All @@ -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)
Expand Down

0 comments on commit 7153eb4

Please sign in to comment.