fix for week number and days till the end of the year

+ formating (clang)
This commit is contained in:
ITCactus 2022-05-25 13:44:25 +02:00
parent e7c0b2c5c2
commit cfaafc1fe2
4 changed files with 48 additions and 52 deletions

View file

@ -22,8 +22,11 @@ CheckboxList::CheckboxList(const uint8_t screenID,
void (Controllers::Settings::*SetOptionIndex)(uint8_t), void (Controllers::Settings::*SetOptionIndex)(uint8_t),
uint8_t (Controllers::Settings::*GetOptionIndex)() const, uint8_t (Controllers::Settings::*GetOptionIndex)() const,
std::array<const char*, MAXLISTITEMS> options) std::array<const char*, MAXLISTITEMS> options)
: Screen(app), screenID {screenID}, settingsController {settingsController}, : Screen(app),
SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex}, screenID {screenID},
settingsController {settingsController},
SetOptionIndex {SetOptionIndex},
GetOptionIndex {GetOptionIndex},
options {options} { options {options} {
settingsController.SetWatchfacesMenu(screenID); settingsController.SetWatchfacesMenu(screenID);

View file

@ -33,7 +33,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app,
heartRateController {heartRateController}, heartRateController {heartRateController},
motionController {motionController} { motionController {motionController} {
label_battery_vallue = lv_label_create(lv_scr_act(), nullptr); label_battery_vallue = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0); lv_obj_align(label_battery_vallue, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text); lv_obj_set_style_local_text_color(label_battery_vallue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
@ -240,30 +239,30 @@ void WatchFaceCasioStyleG7710::Refresh() {
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
// 24h mode: ddmmyyyy, first DOW=Monday; // 24h mode: ddmmyyyy, first DOW=Monday;
lv_label_set_text_fmt( lv_label_set_text_fmt(label_date, "%3d-%2d", day, month);
label_date, "%3d-%2d", day, month); weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number
weekNumberFormat = "%V"; // Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday] // [01,53]. If the week containing 1 January has four or more days in the new year, then it is considered
// week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January
// 4th and the first Thursday of January are always in week 1. [ tm_year, tm_wday, tm_yday]
} else { } else {
// 12h mode: mmddyyyy, first DOW=Sunday; // 12h mode: mmddyyyy, first DOW=Sunday;
lv_label_set_text_fmt( lv_label_set_text_fmt(label_date, "%3d-%2d", month, day);
label_date, "%3d-%2d", month, day); weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the
weekNumberFormat = "%U"; // Replaced by the week number of the year as a decimal number [00,53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] // first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
} }
uint8_t weekNumber; uint8_t weekNumber;
uint16_t dayOfYearNumber, daysTillEndOfYearNumber; uint16_t dayOfYearNumber, daysTillEndOfYearNumber;
std::tm date = {}; time_t ttTime =
date.tm_year = year - 1900; std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get()));
date.tm_mon = static_cast<unsigned>(yearMonthDay.month()) - 1; tm* tmTime = std::localtime(&ttTime);
date.tm_mday = day + 1;
std::mktime( &date );
dayOfYearNumber = date.tm_yday; dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1
daysTillEndOfYearNumber = yearMonthDay.year().is_leap() ? 366 : 365 - dayOfYearNumber; daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber;
char buffer[8]; char buffer[8];
strftime(buffer, 8, weekNumberFormat, &date); strftime(buffer, 8, weekNumberFormat, tmTime);
weekNumber = atoi(buffer); weekNumber = atoi(buffer);
lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString()); lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString());

View file

@ -17,14 +17,12 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
settingsController {settingsController}, settingsController {settingsController},
screens {app, screens {app,
settingsController.GetWatchfacesMenu(), settingsController.GetWatchfacesMenu(),
{ {[this]() -> std::unique_ptr<Screen> {
[this]() -> std::unique_ptr<Screen> {
return CreateScreen1(); return CreateScreen1();
}, },
[this]() -> std::unique_ptr<Screen> { [this]() -> std::unique_ptr<Screen> {
return CreateScreen2(); return CreateScreen2();
} }},
},
Screens::ScreenListModes::UpDown} { Screens::ScreenListModes::UpDown} {
} }
@ -39,16 +37,12 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() { std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"}; std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"};
return std::make_unique<Screens::CheckboxList>(0, 2, app, settingsController, title, return std::make_unique<Screens::CheckboxList>(
symbol, &Controllers::Settings::SetClockFace, 0, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
&Controllers::Settings::GetClockFace,
watchfaces);
} }
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() { std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
std::array<const char*, 4> watchfaces {" Casio G7710", "", "", ""}; std::array<const char*, 4> watchfaces {" Casio G7710", "", "", ""};
return std::make_unique<Screens::CheckboxList>(1, 2, app, settingsController, title, return std::make_unique<Screens::CheckboxList>(
symbol, &Controllers::Settings::SetClockFace, 1, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
&Controllers::Settings::GetClockFace,
watchfaces);
} }