Skip to content

Commit

Permalink
Fix date copy() issue due to default argument for dayOfYear (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikc5000 authored May 30, 2023
1 parent d533373 commit 7b0a9d5
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/io/islandtime/Date.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class Date(
*/
fun copy(
year: Int = this.year,
dayOfYear: Int = this.dayOfYear
dayOfYear: Int
): Date = Date(year, dayOfYear)

companion object {
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/io/islandtime/DateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class DateTime(
*/
fun copy(
year: Int = this.year,
dayOfYear: Int = this.dayOfYear,
dayOfYear: Int,
hour: Int = this.hour,
minute: Int = this.minute,
second: Int = this.second,
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/io/islandtime/OffsetDateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class OffsetDateTime(
*/
fun copy(
year: Int = this.year,
dayOfYear: Int = this.dayOfYear,
dayOfYear: Int,
hour: Int = this.hour,
minute: Int = this.minute,
second: Int = this.second,
Expand Down
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/io/islandtime/ZonedDateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class ZonedDateTime private constructor(
*/
fun copy(
year: Int = this.year,
dayOfYear: Int = this.dayOfYear,
dayOfYear: Int,
hour: Int = this.hour,
minute: Int = this.minute,
second: Int = this.second,
Expand Down
6 changes: 6 additions & 0 deletions core/src/commonTest/kotlin/io/islandtime/DateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DateTest : AbstractIslandTimeTest() {
fun `dates can be constructed from year and day of year`() {
assertEquals(Date(2019, Month.DECEMBER, 1), Date(2019, 335))
assertEquals(Date(2020, Month.DECEMBER, 1), Date(2020, 336))
assertEquals(Date(20200, Month.MARCH, 15), Date(20200, 74))
}

@Test
Expand All @@ -49,6 +50,11 @@ class DateTest : AbstractIslandTimeTest() {
Date(2018, Month.NOVEMBER, 19).copy(year = 2017)
)

assertEquals(
Date(20200, Month.MARCH, 15),
Date(2020, Month.MARCH, 15).copy(year = 20200)
)

assertEquals(
Date(2018, Month.DECEMBER, 19),
Date(2018, Month.NOVEMBER, 19).copy(month = Month.DECEMBER)
Expand Down

0 comments on commit 7b0a9d5

Please sign in to comment.