Skip to content

Commit dc494fe

Browse files
committed
Fix a bug where Julian day 0 was not parsed
1 parent 7b087fb commit dc494fe

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

core/native/src/internal/MonthDayTime.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,28 @@ internal interface DateOfYear {
2727
}
2828

2929
/**
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.
3131
* The number 366 is not supported, as outside the leap years, there are only 365 days in a year.
3232
*/
33-
internal class JulianDayOfYear(val dayOfYear: Int) : DateOfYear {
33+
internal class JulianDayOfYear(val zeroBasedDayOfYear: Int) : DateOfYear {
3434
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+
}
3638
}
3739
override fun toLocalDate(year: Int): LocalDate =
38-
LocalDate(year, 1, 1).plusDays(dayOfYear - 1)
40+
LocalDate(year, 1, 1).plusDays(zeroBasedDayOfYear)
3941

40-
override fun toString(): String = "JulianDayOfYear($dayOfYear)"
42+
override fun toString(): String = "JulianDayOfYear($zeroBasedDayOfYear)"
4143
}
4244

4345
/**
4446
* The day of year, in the 1..365 range. During leap years, 29th February is skipped.
4547
*/
4648
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+
}
4852
// In this form, the `dayOfYear` corresponds exactly to a specific month and day.
4953
// For example, `dayOfYear = 60` is always 1st March, even in leap years.
5054
// We take a non-leap year, as in that case, this is the same as JulianDayOfYear, so regular addition works.

core/nix/src/internal/TzdbOnFilesystem.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
package kotlinx.datetime.internal
77

8-
import kotlinx.datetime.*
9-
import kotlinx.datetime.ZonedDateTime
10-
import kotlinx.datetime.plusSeconds
11-
128
internal class TzdbOnFilesystem(defaultTzdbPath: Path) {
139

1410
internal fun rulesForId(id: String): TimeZoneRules =

core/nix/src/internal/Tzfile.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ internal class PosixTzString(
175175
/**
176176
* Reads a POSIX TZ string from the [reader] if it is present, or returns `null` if it is not.
177177
*
178-
* The string format is described in * https://pubs.opengroup.org/onlinepubs/9699919799/, section 8.3,
178+
* The string format is described in https://pubs.opengroup.org/onlinepubs/9699919799/, section 8.3,
179179
* with additional extensions in https://datatracker.ietf.org/doc/html/rfc8536#section-3.3.1
180180
*
181181
* @throws IllegalArgumentException if the string is invalid

0 commit comments

Comments
 (0)