|
1 | 1 | #include "displayapp/screens/WatchFaceCasioStyleG7710.h" |
2 | 2 |
|
3 | | -#include <date/date.h> |
4 | 3 | #include <lvgl/lvgl.h> |
5 | 4 | #include <cstdio> |
6 | 5 | #include "displayapp/screens/BatteryIcon.h" |
@@ -225,19 +224,14 @@ void WatchFaceCasioStyleG7710::Refresh() { |
225 | 224 | currentDateTime = dateTimeController.CurrentDateTime(); |
226 | 225 |
|
227 | 226 | if (currentDateTime.IsUpdated()) { |
228 | | - auto newDateTime = currentDateTime.Get(); |
| 227 | + auto hour = dateTimeController.Hours(); |
| 228 | + auto minute = dateTimeController.Minutes(); |
| 229 | + auto year = dateTimeController.Year(); |
| 230 | + auto month = dateTimeController.Month(); |
| 231 | + auto dayOfWeek = dateTimeController.DayOfWeek(); |
| 232 | + auto day = dateTimeController.Day(); |
| 233 | + auto dayOfYear = dateTimeController.DayOfYear(); |
229 | 234 |
|
230 | | - auto dp = date::floor<date::days>(newDateTime); |
231 | | - auto time = date::make_time(newDateTime - dp); |
232 | | - auto yearMonthDay = date::year_month_day(dp); |
233 | | - |
234 | | - auto year = static_cast<int>(yearMonthDay.year()); |
235 | | - auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month())); |
236 | | - auto day = static_cast<unsigned>(yearMonthDay.day()); |
237 | | - auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding()); |
238 | | - |
239 | | - uint8_t hour = time.hours().count(); |
240 | | - uint8_t minute = time.minutes().count(); |
241 | 235 | auto weekNumberFormat = "%V"; |
242 | 236 |
|
243 | 237 | if (displayedHour != hour || displayedMinute != minute) { |
@@ -278,22 +272,19 @@ void WatchFaceCasioStyleG7710::Refresh() { |
278 | 272 | // first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday] |
279 | 273 | } |
280 | 274 |
|
281 | | - uint8_t weekNumber; |
282 | | - uint16_t dayOfYearNumber, daysTillEndOfYearNumber; |
283 | | - |
284 | 275 | time_t ttTime = |
285 | 276 | std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get())); |
286 | 277 | tm* tmTime = std::localtime(&ttTime); |
287 | 278 |
|
288 | | - dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1 |
289 | | - daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber; |
| 279 | + int daysInCurrentYear = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 366 : 365; |
| 280 | + uint16_t daysTillEndOfYearNumber = daysInCurrentYear - dayOfYear; |
290 | 281 |
|
291 | 282 | char buffer[8]; |
292 | 283 | strftime(buffer, 8, weekNumberFormat, tmTime); |
293 | | - weekNumber = atoi(buffer); |
| 284 | + uint8_t weekNumber = atoi(buffer); |
294 | 285 |
|
295 | 286 | lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString()); |
296 | | - lv_label_set_text_fmt(label_day_of_year, "%3d-%3d", dayOfYearNumber, daysTillEndOfYearNumber); |
| 287 | + lv_label_set_text_fmt(label_day_of_year, "%3d-%3d", dayOfYear, daysTillEndOfYearNumber); |
297 | 288 | lv_label_set_text_fmt(label_week_number, "WK%02d", weekNumber); |
298 | 289 |
|
299 | 290 | lv_obj_realign(label_day_of_week); |
|
0 commit comments