diff options
author | Krzysztof Adamski <k@japko.eu> | 2021-06-20 11:36:55 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-06-25 10:28:32 +1000 |
commit | 6409bbcb720be6c83d1fef3b7da14094b174a783 (patch) | |
tree | 85a1c8716f933d91e64604b74c71f71eff48a5ef /lib/timeutils/timeutils.c | |
parent | b51ae20c0714ea987ac0988c5d02b59e08048632 (diff) | |
download | micropython-6409bbcb720be6c83d1fef3b7da14094b174a783.tar.gz micropython-6409bbcb720be6c83d1fef3b7da14094b174a783.zip |
mimxrt: Move calc_weekday helper function to timeutils.
This function may be useful for other ports as well so lets move it to
timeutils so it can be reused.
Signed-off-by: Krzysztof Adamski <k@japko.eu>
Diffstat (limited to 'lib/timeutils/timeutils.c')
-rw-r--r-- | lib/timeutils/timeutils.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/timeutils/timeutils.c b/lib/timeutils/timeutils.c index af210d9943..7c74f5fc37 100644 --- a/lib/timeutils/timeutils.c +++ b/lib/timeutils/timeutils.c @@ -213,3 +213,10 @@ mp_uint_t timeutils_mktime_2000(mp_uint_t year, mp_int_t month, mp_int_t mday, } return timeutils_seconds_since_2000(year, month, mday, hours, minutes, seconds); } + +// Calculate the weekday from the date. +// The result is zero based with 0 = Monday. +// by Michael Keith and Tom Craver, 1990. +int timeutils_calc_weekday(int y, int m, int d) { + return ((d += m < 3 ? y-- : y - 2, 23 * m / 9 + d + 4 + y / 4 - y / 100 + y / 400) + 6) % 7; +} |