diff --git a/src/ui/date_time/date_time.cpp b/src/ui/date_time/date_time.cpp index 8af3c8b..252be65 100644 --- a/src/ui/date_time/date_time.cpp +++ b/src/ui/date_time/date_time.cpp @@ -6,47 +6,55 @@ int8_t PaperdinkUIDateClass::fetch_data(const char *time_zone, uint8_t week_star { struct tm timeinfo; time_t epoch; + const int MONTHS[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - for(uint8_t i = 0; i 12){ hour = mil_hour - 12; }else{ hour = mil_hour; } + // Get number of days in a month + month_days = MONTHS[month_num]; + // Handle leap years + if(month_num == 1 && (((year % 4 == 0) && (year % 100 != 0)) || (year%400 == 0))){ + month_days = 29; + } + Serial.printf("Time is %d %d:%d:%d on %s on the %d/%d/%d . It is the month of %s. day_offset: %d\r\n", mil_hour, hour, min, sec, wday, mday, month_num, year, month, day_offset); return 0; } @@ -134,7 +142,7 @@ void PaperdinkUIDateClass::display_calendar(GxEPD2_GFX& display, uint16_t x, uin uint8_t day = 1; for(uint8_t j = 0; j <= 5; j++){ - for(uint8_t i = 1; i <= 7 && day <= 31; i++){ + for(uint8_t i = 1; i <= 7 && day <= month_days; i++){ // you can hack around with this value to align your text properly based on what font, font size etc you are using num_offset = 21; // 21 is what works for me for the first 2 columns if(i >= 3 && i <= 7){ diff --git a/src/ui/date_time/date_time.h b/src/ui/date_time/date_time.h index 8e2397b..899fe1a 100644 --- a/src/ui/date_time/date_time.h +++ b/src/ui/date_time/date_time.h @@ -12,6 +12,7 @@ class PaperdinkUIDateClass : public PaperdinkUIBaseClass public: char wday[4]; char month[4]; + uint8_t month_days; uint8_t month_num; uint8_t mday; uint8_t mil_hour;