Feature/date time mstimer clock (#861)

* Added daylight savings time calculation module with unit testing.

* Added datetime daylight savings time and clock API

* Added basic datetime_local() clock using mstimer as basis and time-sync option.  Integrated clock with ports/stm32f4xx example.
This commit is contained in:
Steve Karg
2024-11-24 11:20:25 -06:00
committed by GitHub
parent cdda524afc
commit fd3be47d86
19 changed files with 992 additions and 93 deletions
+21 -3
View File
@@ -221,6 +221,8 @@ days_since_epoch(uint16_t epoch_year, uint16_t year, uint8_t month, uint8_t day)
days += days_per_month(year, mm);
}
days += day;
/* 'days since' is one less */
days -= 1;
}
return (days);
@@ -243,15 +245,15 @@ void days_since_epoch_to_date(
uint8_t *pDay)
{
uint8_t month = 1;
uint8_t day = 0;
uint8_t day = 1;
uint16_t year;
year = epoch_year;
while (days > days_per_year(year)) {
while (days >= days_per_year(year)) {
days -= days_per_year(year);
year++;
}
while (days > days_per_month(year, month)) {
while (days >= days_per_month(year, month)) {
days -= days_per_month(year, month);
month++;
}
@@ -291,3 +293,19 @@ bool days_date_is_valid(uint16_t year, uint8_t month, uint8_t day)
return (valid);
}
/**
* Returns the day of the week value
*
* @param epoch_day - day of week for epoch day
* @param days - number of days since epoch
* @return day of week 1..7 offset by epoch day
*/
uint8_t days_of_week(uint8_t epoch_day, uint32_t days)
{
uint8_t dow = epoch_day;
dow += (days % 7);
return dow;
}