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

pull/1747/head
Robin Martijn 2019-08-25 22:35:01 +02:00 committed by Alexander Medvednikov
parent d945e9c72e
commit 754b8082fb
1 changed files with 8 additions and 3 deletions

View File

@ -366,9 +366,14 @@ pub fn (t Time) relative() string {
} }
pub fn day_of_week(y, m, d int) int { pub fn day_of_week(y, m, d int) int {
// TODO please no // Sakomotho's algorithm is explained here:
//# return (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7; // https://stackoverflow.com/a/6385934
return 0 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 { pub fn (t Time) day_of_week() int {