Skip to content

Commit 8baa317

Browse files
committed
date: Remove date lib
DateTimeController can provide everything we need.
1 parent 959778d commit 8baa317

14 files changed

Lines changed: 43 additions & 94 deletions

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@
77
[submodule "src/libs/QCBOR"]
88
path = src/libs/QCBOR
99
url = https://github.com/laurencelundblade/QCBOR.git
10-
[submodule "src/libs/date"]
11-
path = src/libs/date
12-
url = https://github.com/HowardHinnant/date.git

src/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,6 @@ set(INCLUDE_FILES
658658
drivers/Cst816s.h
659659
FreeRTOS/portmacro.h
660660
FreeRTOS/portmacro_cmsis.h
661-
libs/date/include/date/tz.h
662-
libs/date/include/date/chrono_io.h
663-
libs/date/include/date/date.h
664-
libs/date/include/date/islamic.h
665-
libs/date/include/date/iso_week.h
666-
libs/date/include/date/julian.h
667-
libs/date/include/date/ptz.h
668-
libs/date/include/date/tz_private.h
669661
displayapp/LittleVgl.h
670662
displayapp/InfiniTimeTheme.h
671663
systemtask/SystemTask.h
@@ -690,7 +682,6 @@ include_directories(
690682
include_directories(SYSTEM
691683
libs/
692684
FreeRTOS/
693-
libs/date/include
694685
libs/mynewt-nimble/porting/npl/freertos/include
695686
libs/mynewt-nimble/nimble/include
696687
libs/mynewt-nimble/porting/nimble/include

src/components/ble/weather/WeatherService.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
You should have received a copy of the GNU General Public License
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
18+
#include <algorithm>
1819
#include <qcbor/qcbor_spiffy_decode.h>
1920
#include "WeatherService.h"
2021
#include "libs/QCBOR/inc/qcbor/qcbor.h"

src/components/datetime/DateTimeController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ namespace Pinetime {
6767
return static_cast<Days>(daysSinceSunday);
6868
}
6969

70+
uint8_t DayOfYear() const {
71+
return localTime.tm_yday + 1;
72+
}
73+
7074
uint8_t Hours() const {
7175
return localTime.tm_hour;
7276
}

src/displayapp/DisplayApp.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22
#include <FreeRTOS.h>
3-
#include <date/date.h>
43
#include <queue.h>
54
#include <task.h>
65
#include <memory>

src/displayapp/DisplayAppRecovery.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <queue.h>
88
#include "components/gfx/Gfx.h"
99
#include "drivers/Cst816s.h"
10-
#include <date/date.h>
1110
#include <drivers/Watchdog.h>
1211
#include <components/motor/MotorController.h>
1312
#include "BootErrors.h"

src/displayapp/screens/Clock.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "displayapp/screens/Clock.h"
22

3-
#include <date/date.h>
43
#include <lvgl/lvgl.h>
54
#include "components/battery/BatteryController.h"
65
#include "components/motion/MotionController.h"

src/displayapp/screens/SystemInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <FreeRTOS.h>
2+
#include <algorithm>
23
#include <task.h>
34
#include "displayapp/screens/SystemInfo.h"
45
#include <lvgl/lvgl.h>

src/displayapp/screens/WatchFaceCasioStyleG7710.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
22

3-
#include <date/date.h>
43
#include <lvgl/lvgl.h>
54
#include <cstdio>
65
#include "displayapp/screens/BatteryIcon.h"
@@ -225,19 +224,14 @@ void WatchFaceCasioStyleG7710::Refresh() {
225224
currentDateTime = dateTimeController.CurrentDateTime();
226225

227226
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();
229234

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();
241235
auto weekNumberFormat = "%V";
242236

243237
if (displayedHour != hour || displayedMinute != minute) {
@@ -278,22 +272,19 @@ void WatchFaceCasioStyleG7710::Refresh() {
278272
// first day of week 1; days in the new year before this are in week 0. [ tm_year, tm_wday, tm_yday]
279273
}
280274

281-
uint8_t weekNumber;
282-
uint16_t dayOfYearNumber, daysTillEndOfYearNumber;
283-
284275
time_t ttTime =
285276
std::chrono::system_clock::to_time_t(std::chrono::time_point_cast<std::chrono::system_clock::duration>(currentDateTime.Get()));
286277
tm* tmTime = std::localtime(&ttTime);
287278

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;
290281

291282
char buffer[8];
292283
strftime(buffer, 8, weekNumberFormat, tmTime);
293-
weekNumber = atoi(buffer);
284+
uint8_t weekNumber = atoi(buffer);
294285

295286
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);
297288
lv_label_set_text_fmt(label_week_number, "WK%02d", weekNumber);
298289

299290
lv_obj_realign(label_day_of_week);

src/displayapp/screens/WatchFaceDigital.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "displayapp/screens/WatchFaceDigital.h"
22

3-
#include <date/date.h>
43
#include <lvgl/lvgl.h>
54
#include <cstdio>
65
#include "displayapp/screens/NotificationIcon.h"
@@ -89,19 +88,12 @@ void WatchFaceDigital::Refresh() {
8988
currentDateTime = dateTimeController.CurrentDateTime();
9089

9190
if (currentDateTime.IsUpdated()) {
92-
auto newDateTime = currentDateTime.Get();
93-
94-
auto dp = date::floor<date::days>(newDateTime);
95-
auto time = date::make_time(newDateTime - dp);
96-
auto yearMonthDay = date::year_month_day(dp);
97-
98-
auto year = static_cast<int>(yearMonthDay.year());
99-
auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month()));
100-
auto day = static_cast<unsigned>(yearMonthDay.day());
101-
auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding());
102-
103-
uint8_t hour = time.hours().count();
104-
uint8_t minute = time.minutes().count();
91+
auto hour = dateTimeController.Hours();
92+
auto minute = dateTimeController.Minutes();
93+
auto year = dateTimeController.Year();
94+
auto month = dateTimeController.Month();
95+
auto dayOfWeek = dateTimeController.DayOfWeek();
96+
auto day = dateTimeController.Day();
10597

10698
if (displayedHour != hour || displayedMinute != minute) {
10799
displayedHour = hour;

0 commit comments

Comments
 (0)