diff --git a/src/main/java/eu/m724/wtapi/object/Twilight.java b/src/main/java/eu/m724/wtapi/object/Twilight.java index 26b5846..ebc4e76 100644 --- a/src/main/java/eu/m724/wtapi/object/Twilight.java +++ b/src/main/java/eu/m724/wtapi/object/Twilight.java @@ -3,25 +3,13 @@ package eu.m724.wtapi.object; import java.time.Duration; import java.time.LocalDate; -public class Twilight { - /** - * The date this object contains times for - */ - public final LocalDate date; - - /** - * Time of sunrise relative to UTC midnight of the date - */ - public final Duration sunrise; - - /** - * Time of sunset relative to UTC midnight of the date - */ - public final Duration sunset; - - public Twilight(LocalDate date, Duration sunrise, Duration sunset) { - this.date = date; - this.sunrise = sunrise; - this.sunset = sunset; +/** + * @param date The date this object contains times for + * @param sunrise Time of sunrise relative to UTC midnight of the date + * @param sunset Time of sunset relative to UTC midnight of the date + */ +public record Twilight(LocalDate date, Duration sunrise, Duration sunset) { + public Duration getDayLength() { + return sunset.minus(sunrise); } } diff --git a/src/test/java/eu/m724/wtapi/twilight/ApproximateTwilightTimeTest.java b/src/test/java/eu/m724/wtapi/twilight/ApproximateTwilightTimeTest.java index 0f03a05..b8aeedd 100644 --- a/src/test/java/eu/m724/wtapi/twilight/ApproximateTwilightTimeTest.java +++ b/src/test/java/eu/m724/wtapi/twilight/ApproximateTwilightTimeTest.java @@ -37,12 +37,12 @@ public class ApproximateTwilightTimeTest { System.out.println(date); System.out.println(coordinates.latitude + " " + coordinates.longitude); - System.out.println("Calculated sunrise: " + date.atStartOfDay().plus(twilight.sunrise)); + System.out.println("Calculated sunrise: " + date.atStartOfDay().plus(twilight.sunrise())); System.out.println("Actual sunrise: " + date.atStartOfDay().plusMinutes(actualSunrise)); - assert Math.abs(twilight.sunrise.toMinutes() - actualSunrise) < ACCEPTABLE_DIFFERENCE; + assert Math.abs(twilight.sunrise().toMinutes() - actualSunrise) < ACCEPTABLE_DIFFERENCE; - System.out.println("Calculated sunset: " + date.atStartOfDay().plus(twilight.sunset)); + System.out.println("Calculated sunset: " + date.atStartOfDay().plus(twilight.sunset())); System.out.println("Actual sunset: " + date.atStartOfDay().plusMinutes(actualSunset)); - assert Math.abs(twilight.sunset.toMinutes() - actualSunset) < ACCEPTABLE_DIFFERENCE; + assert Math.abs(twilight.sunset().toMinutes() - actualSunset) < ACCEPTABLE_DIFFERENCE; } } diff --git a/src/test/java/eu/m724/wtapi/twilight/MockTwilightTimeTest.java b/src/test/java/eu/m724/wtapi/twilight/MockTwilightTimeTest.java index 0b55511..48e3433 100644 --- a/src/test/java/eu/m724/wtapi/twilight/MockTwilightTimeTest.java +++ b/src/test/java/eu/m724/wtapi/twilight/MockTwilightTimeTest.java @@ -16,8 +16,8 @@ public class MockTwilightTimeTest { Coordinates coordinates = new Coordinates(52.4796012, 62.1847245); Twilight twilight = provider.calculateTwilightTime(date, coordinates); - assert twilight.date.equals(date); - assert twilight.sunrise.getSeconds() == -6840; - assert twilight.sunset.getSeconds() == 6840; + assert twilight.date().equals(date); + assert twilight.sunrise().getSeconds() == -6840; + assert twilight.sunset().getSeconds() == 6840; } }