odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.88k stars 606 forks source link

day_of_week bug in core:time/datetime package #3873

Closed adimemir-prog closed 4 months ago

adimemir-prog commented 4 months ago

Context

Steps to Reproduce

build this file below then run the output exe file

package main
import    "core:fmt"
import dt "core:time/datetime"
main :: proc() 
{
    fmt.println("Entering main.")
    fmt.println("-----------------------------------------")

    jan_1st_1ad := dt.Date{day=1,month=1,year=1}
    fmt.println("1th of january 1AD has ordinal", dt.unsafe_date_to_ordinal(jan_1st_1ad))
    fmt.println("its day is",dt.day_of_week(dt.unsafe_date_to_ordinal(jan_1st_1ad)))
    fmt.println("-----------------------------------------")
    jul_4th_2024ad := dt.Date {day=4, month=7, year=2024}
    fmt.println("4th july 2024 has ordinal", dt.unsafe_date_to_ordinal(jul_4th_2024ad))
    fmt.println("its day is", dt.day_of_week(dt.unsafe_date_to_ordinal(jul_4th_2024ad)))
}

Please provide detailed steps for reproducing the issue.

No additional compiler flags are used.

Kelimion commented 4 months ago

Good catch. Thanks.

Kelimion commented 4 months ago

or incrementing the output of the day_of_week procedure by 1 should fix this (a less invasive solution).

It's also the correct solution.