date: Remove date lib

DateTimeController can provide everything we need.
This commit is contained in:
Riku Isokoski
2023-02-23 20:00:58 +02:00
parent 959778d770
commit 8baa317e7e
14 changed files with 43 additions and 94 deletions

View File

@@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
#include <date/date.h>
#include <lvgl/lvgl.h>
#include <cstdio>
#include "displayapp/screens/BatteryIcon.h"
@@ -225,19 +224,14 @@ void WatchFaceCasioStyleG7710::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get();
auto hour = dateTimeController.Hours();
auto minute = dateTimeController.Minutes();
auto year = dateTimeController.Year();
auto month = dateTimeController.Month();
auto dayOfWeek = dateTimeController.DayOfWeek();
auto day = dateTimeController.Day();
auto dayOfYear = dateTimeController.DayOfYear();
auto dp = date::floor<date::days>(newDateTime);
auto time = date::make_time(newDateTime - dp);
auto yearMonthDay = date::year_month_day(dp);
auto year = static_cast<int>(yearMonthDay.year());
auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month()));
auto day = static_cast<unsigned>(yearMonthDay.day());
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
uint8_t hour = time.hours().count();
uint8_t minute = time.minutes().count();
auto weekNumberFormat = "%V";
if (displayedHour != hour || displayedMinute != minute) {
@@ -278,22 +272,19 @@ void WatchFaceCasioStyleG7710::Refresh() {
// 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;
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 = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1
daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber;
int daysInCurrentYear = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 366 : 365;
uint16_t daysTillEndOfYearNumber = daysInCurrentYear - dayOfYear;
char buffer[8];
strftime(buffer, 8, weekNumberFormat, tmTime);
weekNumber = atoi(buffer);
uint8_t weekNumber = atoi(buffer);
lv_label_set_text_fmt(label_day_of_week, "%s", dateTimeController.DayOfWeekShortToString());
lv_label_set_text_fmt(label_day_of_year, "%3d-%3d", dayOfYearNumber, daysTillEndOfYearNumber);
lv_label_set_text_fmt(label_day_of_year, "%3d-%3d", dayOfYear, daysTillEndOfYearNumber);
lv_label_set_text_fmt(label_week_number, "WK%02d", weekNumber);
lv_obj_realign(label_day_of_week);