@@ -27,24 +27,28 @@ internal interface DateOfYear {
27
27
}
28
28
29
29
/* *
30
- * The day of year, in the 1 ..365 range. During leap years, 29th February is counted as the 60th day of the year.
30
+ * The day of year, in the 0 ..365 range. During leap years, 29th February is counted as the 60th day of the year.
31
31
* The number 366 is not supported, as outside the leap years, there are only 365 days in a year.
32
32
*/
33
- internal class JulianDayOfYear (val dayOfYear : Int ) : DateOfYear {
33
+ internal class JulianDayOfYear (val zeroBasedDayOfYear : Int ) : DateOfYear {
34
34
init {
35
- require(dayOfYear in 1 .. 365 )
35
+ require(zeroBasedDayOfYear in 0 .. 365 ) {
36
+ " Expected a value in 1..365 for the Julian day-of-year, but got $zeroBasedDayOfYear "
37
+ }
36
38
}
37
39
override fun toLocalDate (year : Int ): LocalDate =
38
- LocalDate (year, 1 , 1 ).plusDays(dayOfYear - 1 )
40
+ LocalDate (year, 1 , 1 ).plusDays(zeroBasedDayOfYear )
39
41
40
- override fun toString (): String = " JulianDayOfYear($dayOfYear )"
42
+ override fun toString (): String = " JulianDayOfYear($zeroBasedDayOfYear )"
41
43
}
42
44
43
45
/* *
44
46
* The day of year, in the 1..365 range. During leap years, 29th February is skipped.
45
47
*/
46
48
internal fun JulianDayOfYearSkippingLeapDate (dayOfYear : Int ) : DateOfYear {
47
- require(dayOfYear in 1 .. 365 )
49
+ require(dayOfYear in 1 .. 365 ) {
50
+ " Expected a value in 1..365 for the Julian day-of-year (skipping the leap date), but got $dayOfYear "
51
+ }
48
52
// In this form, the `dayOfYear` corresponds exactly to a specific month and day.
49
53
// For example, `dayOfYear = 60` is always 1st March, even in leap years.
50
54
// We take a non-leap year, as in that case, this is the same as JulianDayOfYear, so regular addition works.
0 commit comments