1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

calendar: make get_day_of_week() public

This commit is contained in:
Gabor Kiss-Vamosi 2020-12-20 10:55:20 +01:00
parent aac672e88b
commit 2bf91dbbb5
2 changed files with 30 additions and 21 deletions

View File

@ -365,6 +365,27 @@ const char ** lv_calendar_get_month_names(const lv_obj_t * calendar)
return ext->month_names;
}
/**
* Get the day of the week
* @param year a year
* @param month a month (1..12)
* @param day a day (1..31)
* @return [0..6] which means [Sun..Sat] or [Mon..Sun] depending on LV_CALENDAR_WEEK_STARTS_MONDAY
*/
uint8_t lv_calendar_get_day_of_week(uint32_t year, uint32_t month, uint32_t day)
{
uint32_t a = month < 3 ? 1 : 0;
uint32_t b = year - a;
#if LV_CALENDAR_WEEK_STARTS_MONDAY
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + b + (b / 4) - (b / 100) + (b / 400) - 1) % 7;
#else
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + b + (b / 4) - (b / 100) + (b / 400)) % 7;
#endif
return day_of_week;
}
/*=====================
* Other functions
*====================*/
@ -1067,25 +1088,4 @@ static uint8_t is_leap_year(uint32_t year)
return (year % 4) || ((year % 100 == 0) && (year % 400)) ? 0 : 1;
}
/**
* Get the day of the week
* @param year a year
* @param month a month
* @param day a day
* @return [0..6] which means [Sun..Sat] or [Mon..Sun] depending on LV_CALENDAR_WEEK_STARTS_MONDAY
*/
static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day)
{
uint32_t a = month < 3 ? 1 : 0;
uint32_t b = year - a;
#if LV_CALENDAR_WEEK_STARTS_MONDAY
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + b + (b / 4) - (b / 100) + (b / 400) - 1) % 7;
#else
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) + b + (b / 4) - (b / 100) + (b / 400)) % 7;
#endif
return day_of_week;
}
#endif

View File

@ -182,6 +182,15 @@ const char ** lv_calendar_get_day_names(const lv_obj_t * calendar);
*/
const char ** lv_calendar_get_month_names(const lv_obj_t * calendar);
/**
* Get the day of the week
* @param year a year
* @param month a month (1..12)
* @param day a day (1..31)
* @return [0..6] which means [Sun..Sat] or [Mon..Sun] depending on LV_CALENDAR_WEEK_STARTS_MONDAY
*/
uint8_t lv_calendar_get_day_of_week(uint32_t year, uint32_t month, uint32_t day);
/*=====================
* Other functions
*====================*/