fix for week number and days till the end of the year
+ formating (clang)
This commit is contained in:
parent
e7c0b2c5c2
commit
cfaafc1fe2
|
@ -20,10 +20,13 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
const char* optionsTitle,
|
||||
const char* optionsSymbol,
|
||||
void (Controllers::Settings::*SetOptionIndex)(uint8_t),
|
||||
uint8_t (Controllers::Settings::*GetOptionIndex )() const,
|
||||
uint8_t (Controllers::Settings::*GetOptionIndex)() const,
|
||||
std::array<const char*, MAXLISTITEMS> options)
|
||||
: Screen(app), screenID {screenID}, settingsController {settingsController},
|
||||
SetOptionIndex {SetOptionIndex}, GetOptionIndex {GetOptionIndex},
|
||||
: Screen(app),
|
||||
screenID {screenID},
|
||||
settingsController {settingsController},
|
||||
SetOptionIndex {SetOptionIndex},
|
||||
GetOptionIndex {GetOptionIndex},
|
||||
options {options} {
|
||||
|
||||
settingsController.SetWatchfacesMenu(screenID);
|
||||
|
@ -87,7 +90,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
|
|||
lv_obj_set_event_cb(cbOption[i], event_handler);
|
||||
SetRadioButtonStyle(cbOption[i]);
|
||||
|
||||
if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MAXLISTITEMS*screenID) == i) {
|
||||
if (static_cast<unsigned int>((settingsController.*GetOptionIndex)() - MAXLISTITEMS * screenID) == i) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +108,7 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
|||
if (strcmp(options[i], "")) {
|
||||
if (object == cbOption[i]) {
|
||||
lv_checkbox_set_checked(cbOption[i], true);
|
||||
(settingsController.*SetOptionIndex)(MAXLISTITEMS*screenID + i);
|
||||
(settingsController.*SetOptionIndex)(MAXLISTITEMS * screenID + i);
|
||||
} else {
|
||||
lv_checkbox_set_checked(cbOption[i], false);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ WatchFaceCasioStyleG7710::WatchFaceCasioStyleG7710(DisplayApp* app,
|
|||
heartRateController {heartRateController},
|
||||
motionController {motionController} {
|
||||
|
||||
|
||||
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_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 (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
|
||||
// 24h mode: ddmmyyyy, first DOW=Monday;
|
||||
lv_label_set_text_fmt(
|
||||
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 [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]
|
||||
lv_label_set_text_fmt(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
|
||||
// [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 {
|
||||
// 12h mode: mmddyyyy, first DOW=Sunday;
|
||||
lv_label_set_text_fmt(
|
||||
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 first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
|
||||
lv_label_set_text_fmt(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
|
||||
// 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;
|
||||
uint16_t dayOfYearNumber, daysTillEndOfYearNumber;
|
||||
|
||||
std::tm date = {};
|
||||
date.tm_year = year - 1900;
|
||||
date.tm_mon = static_cast<unsigned>(yearMonthDay.month()) - 1;
|
||||
date.tm_mday = day + 1;
|
||||
std::mktime( &date );
|
||||
time_t ttTime =
|
||||
std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get()));
|
||||
tm* tmTime = std::localtime(&ttTime);
|
||||
|
||||
dayOfYearNumber = date.tm_yday;
|
||||
daysTillEndOfYearNumber = yearMonthDay.year().is_leap() ? 366 : 365 - dayOfYearNumber;
|
||||
dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1
|
||||
daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber;
|
||||
|
||||
char buffer[8];
|
||||
strftime(buffer, 8, weekNumberFormat, &date);
|
||||
strftime(buffer, 8, weekNumberFormat, tmTime);
|
||||
weekNumber = atoi(buffer);
|
||||
|
||||
lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString());
|
||||
|
|
|
@ -17,14 +17,12 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine
|
|||
settingsController {settingsController},
|
||||
screens {app,
|
||||
settingsController.GetWatchfacesMenu(),
|
||||
{
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
{[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen1();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return CreateScreen2();
|
||||
}
|
||||
},
|
||||
}},
|
||||
Screens::ScreenListModes::UpDown} {
|
||||
}
|
||||
|
||||
|
@ -39,16 +37,12 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
|
||||
std::array<const char*, 4> watchfaces {" Digital face", " Analog face", " PineTimeStyle", " Terminal"};
|
||||
return std::make_unique<Screens::CheckboxList>(0, 2, app, settingsController, title,
|
||||
symbol, &Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
watchfaces);
|
||||
return std::make_unique<Screens::CheckboxList>(
|
||||
0, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
|
||||
std::array<const char*, 4> watchfaces {" Casio G7710", "", "", ""};
|
||||
return std::make_unique<Screens::CheckboxList>(1, 2, app, settingsController, title,
|
||||
symbol, &Controllers::Settings::SetClockFace,
|
||||
&Controllers::Settings::GetClockFace,
|
||||
watchfaces);
|
||||
return std::make_unique<Screens::CheckboxList>(
|
||||
1, 2, app, settingsController, title, symbol, &Controllers::Settings::SetClockFace, &Controllers::Settings::GetClockFace, watchfaces);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user