kotlinx-datetime icon indicating copy to clipboard operation
kotlinx-datetime copied to clipboard

DST time zone offsets wrong pre-2006 on MingwX64

Open jeffdgr8 opened this issue 1 year ago • 1 comments
trafficstars

Running the following code:

logTzDst(TimeZone.of("America/Los_Angeles"))
logTzDst(TimeZone.of("America/Denver"))
logTzDst(TimeZone.of("America/Chicago"))
logTzDst(TimeZone.of("America/New_York"))

private fun logTzDst(timeZone: TimeZone) {
    println(timeZone)
    var last: String? = null
    for (y in 2024 downTo 1900) {
        val date = LocalDate.parse("$y-08-01")
            .atTime(0, 0)
            .toInstant(timeZone)
        val offset = date.toString().substring(11)
        if (offset != last) {
            println(date)
            println("...")
        }
        last = offset
    }
    println()
}

MingwX64 0.6.0 doesn't adjust for daylight savings time before 2006:

America/Los_Angeles
2024-08-01T07:00:00Z
...
2005-08-01T08:00:00Z
...

America/Denver
2024-08-01T06:00:00Z
...
2005-08-01T07:00:00Z
...

America/Chicago
2024-08-01T05:00:00Z
...
2005-08-01T06:00:00Z
...

America/New_York
2024-08-01T04:00:00Z
...
2005-08-01T05:00:00Z
...

MingwX64 0.5.0 naively adjusts for daylight savings time for all years, which is mostly correct for the previous century, but not for some of those years and pre-1918:

America/Los_Angeles
2024-08-01T07:00:00Z
...

America/Denver
2024-08-01T06:00:00Z
...

America/Chicago
2024-08-01T05:00:00Z
...

America/New_York
2024-08-01T04:00:00Z
...

JVM/iOS/macOS/Linux properly adjust for daylight savings time in the correct years:

America/Los_Angeles
2024-08-01T07:00:00Z
...
1949-08-01T08:00:00Z
...
1948-08-01T07:00:00Z
...
1947-08-01T08:00:00Z
...
1945-08-01T07:00:00Z
...
1941-08-01T08:00:00Z
...
1919-08-01T07:00:00Z
...
1917-08-01T08:00:00Z
...

America/Denver
2024-08-01T06:00:00Z
...
1964-08-01T07:00:00Z
...
1945-08-01T06:00:00Z
...
1941-08-01T07:00:00Z
...
1920-08-01T06:00:00Z
...
1917-08-01T07:00:00Z
...

America/Chicago
2024-08-01T05:00:00Z
...
1917-08-01T06:00:00Z
...

America/New_York
2024-08-01T04:00:00Z
...
1917-08-01T05:00:00Z
...

jeffdgr8 avatar Sep 27 '24 17:09 jeffdgr8