Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,9 @@ fun Episode.addDate(date: Instant?) {
this.date = date?.toEpochMilliseconds()
}

@Prerelease
fun Int.toYear(): LocalDate = LocalDate(this, 1, 1)

// Deprecate after next stable
/* @Deprecated(
message = "Use addDate with LocalDate, Instant, or String instead.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.lagradost.cloudstream3

import kotlinx.datetime.LocalDate
import kotlinx.datetime.number
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

class IntToYearTest {

@Test
fun toYearReturnsFirstOfJanuary() {
val result = 2026.toYear()
assertEquals(LocalDate(2026, 1, 1), result)
}

@Test
fun toYearSetsCorrectYear() {
val result = 1999.toYear()
assertEquals(1999, result.year)
}

@Test
fun toYearSetsMonthToJanuary() {
val result = 2026.toYear()
assertEquals(1, result.month.number)
}

@Test
fun toYearSetsDayToFirst() {
val result = 2026.toYear()
assertEquals(1, result.day)
}

@Test
fun toYearHandlesLeapYear() {
val result = 2028.toYear()
assertEquals(LocalDate(2028, 1, 1), result)
}

@Test
fun toYearHandlesEpochYear() {
val result = 1970.toYear()
assertEquals(LocalDate(1970, 1, 1), result)
}

@Test
fun toYearHandlesFarPastYear() {
val result = 1.toYear()
assertEquals(LocalDate(1, 1, 1), result)
}

@Test
fun toYearHandlesFarFutureYear() {
val result = 9999.toYear()
assertEquals(LocalDate(9999, 1, 1), result)
}

@Test
fun toYearDifferentYearsProduceDifferentDates() {
assertFalse(2025.toYear() == 2026.toYear())
}
}
Loading