Date
Implement a function to get the number of days from 0000-00-00
to yyyy-mm-dd
.
Accumulate
Magic Formula
When m=1
or m=2
(January or February), we let m=13
or m=14
and let y
decreased by 1. Imagine it is 13th or 14th month of the last year. By doing that, we let the magical formula also work for those two months. (153 * m + 8) // 5
is just a carefully designed way to record the days of each month. More specifically, it is designed to record the difference of days between two months. Suppose we have March 1st and April 1st, (153 * 3 + 8) // 5 = 93
while (153 * 4 + 8) // 5 = 124
, the difference is 31 which is the number of days in March. Suppose we have April 1st to May 1st, (153 * 4 + 8) // 5 = 124
and (153 * 5 + 8) // 5 = 154
, the difference is now 30 which is the number of days in April. You can also check other months.
Problems
Last updated