time/vlib: fix day_of_week() with sakamoto's algorithm
parent
d945e9c72e
commit
754b8082fb
|
@ -366,9 +366,14 @@ pub fn (t Time) relative() string {
|
|||
}
|
||||
|
||||
pub fn day_of_week(y, m, d int) int {
|
||||
// TODO please no
|
||||
//# return (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7;
|
||||
return 0
|
||||
// Sakomotho's algorithm is explained here:
|
||||
// https://stackoverflow.com/a/6385934
|
||||
t := [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
|
||||
mut sy := y
|
||||
if (m < 3) {
|
||||
sy = sy - 1
|
||||
}
|
||||
return ( sy + sy/4 - sy/100 + sy/400 + t[m-1] + d - 1) % 7 + 1
|
||||
}
|
||||
|
||||
pub fn (t Time) day_of_week() int {
|
||||
|
|
Loading…
Reference in New Issue