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

3
.gitmodules vendored
View File

@ -7,6 +7,3 @@
[submodule "src/libs/QCBOR"] [submodule "src/libs/QCBOR"]
path = src/libs/QCBOR path = src/libs/QCBOR
url = https://github.com/laurencelundblade/QCBOR.git url = https://github.com/laurencelundblade/QCBOR.git
[submodule "src/libs/date"]
path = src/libs/date
url = https://github.com/HowardHinnant/date.git

View File

@ -658,14 +658,6 @@ set(INCLUDE_FILES
drivers/Cst816s.h drivers/Cst816s.h
FreeRTOS/portmacro.h FreeRTOS/portmacro.h
FreeRTOS/portmacro_cmsis.h FreeRTOS/portmacro_cmsis.h
libs/date/include/date/tz.h
libs/date/include/date/chrono_io.h
libs/date/include/date/date.h
libs/date/include/date/islamic.h
libs/date/include/date/iso_week.h
libs/date/include/date/julian.h
libs/date/include/date/ptz.h
libs/date/include/date/tz_private.h
displayapp/LittleVgl.h displayapp/LittleVgl.h
displayapp/InfiniTimeTheme.h displayapp/InfiniTimeTheme.h
systemtask/SystemTask.h systemtask/SystemTask.h
@ -690,7 +682,6 @@ include_directories(
include_directories(SYSTEM include_directories(SYSTEM
libs/ libs/
FreeRTOS/ FreeRTOS/
libs/date/include
libs/mynewt-nimble/porting/npl/freertos/include libs/mynewt-nimble/porting/npl/freertos/include
libs/mynewt-nimble/nimble/include libs/mynewt-nimble/nimble/include
libs/mynewt-nimble/porting/nimble/include libs/mynewt-nimble/porting/nimble/include

View File

@ -15,6 +15,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <algorithm>
#include <qcbor/qcbor_spiffy_decode.h> #include <qcbor/qcbor_spiffy_decode.h>
#include "WeatherService.h" #include "WeatherService.h"
#include "libs/QCBOR/inc/qcbor/qcbor.h" #include "libs/QCBOR/inc/qcbor/qcbor.h"

View File

@ -67,6 +67,10 @@ namespace Pinetime {
return static_cast<Days>(daysSinceSunday); return static_cast<Days>(daysSinceSunday);
} }
uint8_t DayOfYear() const {
return localTime.tm_yday + 1;
}
uint8_t Hours() const { uint8_t Hours() const {
return localTime.tm_hour; return localTime.tm_hour;
} }

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <date/date.h>
#include <queue.h> #include <queue.h>
#include <task.h> #include <task.h>
#include <memory> #include <memory>

View File

@ -7,7 +7,6 @@
#include <queue.h> #include <queue.h>
#include "components/gfx/Gfx.h" #include "components/gfx/Gfx.h"
#include "drivers/Cst816s.h" #include "drivers/Cst816s.h"
#include <date/date.h>
#include <drivers/Watchdog.h> #include <drivers/Watchdog.h>
#include <components/motor/MotorController.h> #include <components/motor/MotorController.h>
#include "BootErrors.h" #include "BootErrors.h"

View File

@ -1,6 +1,5 @@
#include "displayapp/screens/Clock.h" #include "displayapp/screens/Clock.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "components/battery/BatteryController.h" #include "components/battery/BatteryController.h"
#include "components/motion/MotionController.h" #include "components/motion/MotionController.h"

View File

@ -1,4 +1,5 @@
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <algorithm>
#include <task.h> #include <task.h>
#include "displayapp/screens/SystemInfo.h" #include "displayapp/screens/SystemInfo.h"
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>

View File

@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceCasioStyleG7710.h" #include "displayapp/screens/WatchFaceCasioStyleG7710.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <cstdio> #include <cstdio>
#include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BatteryIcon.h"
@ -225,19 +224,14 @@ void WatchFaceCasioStyleG7710::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { 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"; auto weekNumberFormat = "%V";
if (displayedHour != hour || displayedMinute != minute) { 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] // 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 = time_t ttTime =
std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get())); std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get()));
tm* tmTime = std::localtime(&ttTime); tm* tmTime = std::localtime(&ttTime);
dayOfYearNumber = tmTime->tm_yday + 1; // tm_yday day of year [0,365] => yday+1 int daysInCurrentYear = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 ? 366 : 365;
daysTillEndOfYearNumber = (yearMonthDay.year().is_leap() ? 366 : 365) - dayOfYearNumber; uint16_t daysTillEndOfYearNumber = daysInCurrentYear - dayOfYear;
char buffer[8]; char buffer[8];
strftime(buffer, 8, weekNumberFormat, tmTime); 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_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_label_set_text_fmt(label_week_number, "WK%02d", weekNumber);
lv_obj_realign(label_day_of_week); lv_obj_realign(label_day_of_week);

View File

@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceDigital.h" #include "displayapp/screens/WatchFaceDigital.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <cstdio> #include <cstdio>
#include "displayapp/screens/NotificationIcon.h" #include "displayapp/screens/NotificationIcon.h"
@ -89,19 +88,12 @@ void WatchFaceDigital::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto hour = dateTimeController.Hours();
auto minute = dateTimeController.Minutes();
auto dp = date::floor<date::days>(newDateTime); auto year = dateTimeController.Year();
auto time = date::make_time(newDateTime - dp); auto month = dateTimeController.Month();
auto yearMonthDay = date::year_month_day(dp); auto dayOfWeek = dateTimeController.DayOfWeek();
auto day = dateTimeController.Day();
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();
if (displayedHour != hour || displayedMinute != minute) { if (displayedHour != hour || displayedMinute != minute) {
displayedHour = hour; displayedHour = hour;

View File

@ -1,6 +1,5 @@
#include "displayapp/screens/WatchFaceInfineat.h" #include "displayapp/screens/WatchFaceInfineat.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <cstdio> #include <cstdio>
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
@ -314,19 +313,12 @@ void WatchFaceInfineat::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto hour = dateTimeController.Hours();
auto minute = dateTimeController.Minutes();
auto dp = date::floor<date::days>(newDateTime); auto year = dateTimeController.Year();
auto time = date::make_time(newDateTime - dp); auto month = dateTimeController.Month();
auto yearMonthDay = date::year_month_day(dp); auto dayOfWeek = dateTimeController.DayOfWeek();
auto day = dateTimeController.Day();
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());
int hour = time.hours().count();
auto minute = time.minutes().count();
char minutesChar[3]; char minutesChar[3];
sprintf(minutesChar, "%02d", static_cast<int>(minute)); sprintf(minutesChar, "%02d", static_cast<int>(minute));

View File

@ -20,7 +20,6 @@
*/ */
#include "displayapp/screens/WatchFacePineTimeStyle.h" #include "displayapp/screens/WatchFacePineTimeStyle.h"
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include <cstdio> #include <cstdio>
#include <displayapp/Colors.h> #include <displayapp/Colors.h>
@ -448,20 +447,13 @@ void WatchFacePineTimeStyle::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto hour = dateTimeController.Hours();
auto minute = dateTimeController.Minutes();
auto dp = date::floor<date::days>(newDateTime); auto second = dateTimeController.Seconds();
auto time = date::make_time(newDateTime - dp); auto year = dateTimeController.Year();
auto yearMonthDay = date::year_month_day(dp); auto month = dateTimeController.Month();
auto dayOfWeek = dateTimeController.DayOfWeek();
auto year = static_cast<int>(yearMonthDay.year()); auto day = dateTimeController.Day();
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();
uint8_t second = time.seconds().count();
if (displayedHour != hour || displayedMinute != minute) { if (displayedHour != hour || displayedMinute != minute) {
displayedHour = hour; displayedHour = hour;

View File

@ -1,4 +1,3 @@
#include <date/date.h>
#include <lvgl/lvgl.h> #include <lvgl/lvgl.h>
#include "displayapp/screens/WatchFaceTerminal.h" #include "displayapp/screens/WatchFaceTerminal.h"
#include "displayapp/screens/BatteryIcon.h" #include "displayapp/screens/BatteryIcon.h"
@ -108,20 +107,13 @@ void WatchFaceTerminal::Refresh() {
currentDateTime = dateTimeController.CurrentDateTime(); currentDateTime = dateTimeController.CurrentDateTime();
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {
auto newDateTime = currentDateTime.Get(); auto hour = dateTimeController.Hours();
auto minute = dateTimeController.Minutes();
auto dp = date::floor<date::days>(newDateTime); auto second = dateTimeController.Seconds();
auto time = date::make_time(newDateTime - dp); auto year = dateTimeController.Year();
auto yearMonthDay = date::year_month_day(dp); auto month = dateTimeController.Month();
auto dayOfWeek = dateTimeController.DayOfWeek();
auto year = static_cast<int>(yearMonthDay.year()); auto day = dateTimeController.Day();
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();
uint8_t second = time.seconds().count();
if (displayedHour != hour || displayedMinute != minute || displayedSecond != second) { if (displayedHour != hour || displayedMinute != minute || displayedSecond != second) {
displayedHour = hour; displayedHour = hour;

@ -1 +0,0 @@
Subproject commit 9502bc27a3b32fa5759ea82a76c22551620ebcd2