mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 11:40:18 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
b51ae20c07
commit
6409bbcb72
@@ -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;
|
||||
}
|
||||
|
||||
@@ -100,4 +100,6 @@ static inline int64_t timeutils_nanoseconds_since_epoch_to_nanoseconds_since_197
|
||||
|
||||
#endif
|
||||
|
||||
int timeutils_calc_weekday(int y, int m, int d);
|
||||
|
||||
#endif // MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H
|
||||
|
||||
Reference in New Issue
Block a user