package com.ponzischeme89.memby.ui

import com.ponzischeme89.memby.ui.detail.formatAirDate
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class AirDateTest {
    @Test
    fun `an Emby premiere date reads as a day, month and year`() {
        assertEquals("12 Mar 2024", formatAirDate("2024-03-12T00:00:00.0000000Z"))
        assertEquals("1 Jan 2019", formatAirDate("2019-01-01T00:00:00Z"))
        assertEquals("31 Dec 2026", formatAirDate("2026-12-31"))
    }

    /**
     * Emby writes a premiere as midnight UTC. Reading the date half literally is what stops
     * an episode broadcast on the 12th being listed as the 11th on every set west of
     * Greenwich, so a timestamp late in the day must still yield its own date.
     */
    @Test
    fun `the date is taken literally, never shifted into the set's own zone`() {
        assertEquals("12 Mar 2024", formatAirDate("2024-03-12T23:30:00Z"))
    }

    @Test
    fun `anything unusable is no date rather than a wrong one`() {
        assertNull(formatAirDate(null))
        assertNull(formatAirDate(""))
        assertNull(formatAirDate("   "))
        assertNull(formatAirDate("2024"))
        assertNull(formatAirDate("not a date at all"))
        assertNull(formatAirDate("2024/03/12"))
        assertNull(formatAirDate("2024-13-01T00:00:00Z"))
        assertNull(formatAirDate("2024-03-32T00:00:00Z"))
        assertNull(formatAirDate("20xx-03-12"))
    }
}
