Instant, ZonedDateTime and daylight savings

/**
 * This class and test exists because I had to explain these concepts so many times.
 */
class TimeZonesTest {
    private val romania = ZoneId.of("Europe/Bucharest")

    /**
     * In Romania, Daylight Saving Changes ended in 2021-10-31--04-00-00 (utc+3).
     * At that time, the time changed to            2021-10-31--03-00-00 (utc+2).
     * This shows an example of how ZonedDateTime and Instant work.
     */
    @Test
    fun `Instant, ZonedDateTime and daylight savings`() {
        val beforeDstZ = ZonedDateTime.of(2021, 10, 31, 3, 59, 59, 0, romania)
        val afterDstZ = beforeDstZ.plusSeconds(1)
        val beforeDstZ2I = beforeDstZ.toInstant()
        val afterDstZ2I = afterDstZ.toInstant()

        println(beforeDstZ)
        println(afterDstZ)
        println(beforeDstZ2I)
        println(afterDstZ2I)

        println()
        println()
        println()
        println()

        val beforeDstI = Instant.parse("2021-10-31T00:59:59Z")
        val afterDstI = beforeDstI.plusSeconds(1)
        val beforeDstI2Z = beforeDstI.atZone(romania)
        val afterDstI2Z = afterDstI.atZone(romania)
        println(beforeDstI)
        println(afterDstI)
        println(beforeDstI2Z)
        println(afterDstI2Z)

        assertThat(beforeDstZ)
            .isEqualTo("2021-10-31T00:59:59Z")
            .isEqualTo("2021-10-31T03:59:59+03:00[Europe/Bucharest]")
            .isEqualTo(beforeDstI.toString())
            .isEqualTo(beforeDstI2Z)
            .isEqualTo(beforeDstZ2I.toString())
            .isBefore("2021-10-31T01:00:00Z")
            .isBefore("2021-10-31T03:00+02:00[Europe/Bucharest]")
            .isBefore(afterDstI.toString())
            .isBefore(afterDstI2Z)
            .isBefore(afterDstZ2I.toString())
    }
}