[go: up one dir, main page]

Tran Sang Dev Blog

A real-life engineer blog

Sakamoto algorithm to calculate day of week

Sakamoto algorithm to calculate day of week

If year is non-negative: Sakamoto algorithm implementation in C++: 0 = sunday, 1 = monday, ..., 6 = saturday. static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; int dow(int y, int m, int d) { y -= m<3; return (d + t[m-1] + y + y/4 - y/100 + y/400) % 7; } In Javascript: // m = 1, 2, ..., 12 // result: 0 = sun, 1 = mon, ..., 6 = sat function dayOfWeek(y, m, d) { if (m<3) y-- m = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4][m-1] return (d + m + y + ~~(y/4) - ~~(y/100) + ~~(y/400)) % 7 }
2 min read
Recommended flutter resources

Recommended flutter resources

I list several useful resources for Flutter dev. * Official home page: https://docs.flutter.dev/ * Flutter Layout Cheat Sheet: https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e, snapshot. * From the same author, Flutter Animation Cheat Sheet: https://medium.com/flutter-community/flutter-animations-cheat-sheet-7f8cebfb850c, snapshot, demo. * Inherited widget in deep (in Japanese, Flutter大学): https://blog.flutteruniv.
2 min read