1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time/vlib: fix day_of_week() with sakamoto's algorithm

This commit is contained in:
Robin Martijn 2019-08-25 22:35:01 +02:00 committed by Alexander Medvednikov
parent d945e9c72e
commit 754b8082fb

View File

@ -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 {