mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix leap year bug
This commit is contained in:
@@ -369,6 +369,10 @@ datetime_to_time :: proc "contextless" (year, month, day, hour, minute, second:
|
|||||||
mod = year % divisor
|
mod = year % divisor
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
_is_leap_year :: proc "contextless" (year: int) -> bool {
|
||||||
|
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
|
|
||||||
@@ -395,6 +399,10 @@ datetime_to_time :: proc "contextless" (year, month, day, hour, minute, second:
|
|||||||
|
|
||||||
days += int(days_before[_m]) + _d
|
days += int(days_before[_m]) + _d
|
||||||
|
|
||||||
|
if _is_leap_year(year) && _m >= 2 {
|
||||||
|
days += 1
|
||||||
|
}
|
||||||
|
|
||||||
s += i64(days) * SECONDS_PER_DAY
|
s += i64(days) * SECONDS_PER_DAY
|
||||||
s += i64(hour) * SECONDS_PER_HOUR
|
s += i64(hour) * SECONDS_PER_HOUR
|
||||||
s += i64(minute) * SECONDS_PER_MINUTE
|
s += i64(minute) * SECONDS_PER_MINUTE
|
||||||
|
|||||||
Reference in New Issue
Block a user