Fix date/time conversion from CTS to internal date/time representation.
This commit is contained in:
parent
824b8a7ebd
commit
64014f03ee
3 changed files with 13 additions and 15 deletions
|
@ -7,25 +7,23 @@ using namespace Pinetime::Controllers;
|
|||
|
||||
void DateTime::SetTime(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute,
|
||||
uint8_t second, uint32_t systickCounter) {
|
||||
std::tm tm = { /* .tm_sec = */ second,
|
||||
/* .tm_min = */ minute,
|
||||
/* .tm_hour = */ hour,
|
||||
/* .tm_mday = */ day,
|
||||
/* .tm_mon = */ month - 1,
|
||||
/* .tm_year = */ year - 1900,
|
||||
};
|
||||
tm.tm_isdst = -1; // Use DST value from local time zone
|
||||
currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
||||
|
||||
currentDateTime = {};
|
||||
currentDateTime += date::years( year-1970);
|
||||
currentDateTime += date::days( day - 1);
|
||||
currentDateTime += date::months( month - 1);
|
||||
|
||||
currentDateTime += std::chrono::hours(hour);
|
||||
currentDateTime += std::chrono::minutes (minute);
|
||||
currentDateTime += std::chrono::seconds (second);
|
||||
|
||||
currentDateTime -= std::chrono::hours(3); // TODO WHYYYY?
|
||||
NRF_LOG_INFO("%d %d %d ", day, month, year);
|
||||
NRF_LOG_INFO("%d %d %d ", hour, minute, second);
|
||||
previousSystickCounter = systickCounter;
|
||||
|
||||
UpdateTime(systickCounter);
|
||||
NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second);
|
||||
NRF_LOG_INFO("* %d %d %d ", this->day, this->month, this->year);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void DateTime::UpdateTime(uint32_t systickCounter) {
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Pinetime {
|
|||
uint8_t Minutes() const { return minute; }
|
||||
uint8_t Seconds() const { return second; }
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> CurrentDateTime() const { return currentDateTime; }
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const { return currentDateTime; }
|
||||
private:
|
||||
uint16_t year = 0;
|
||||
Months month = Months::Unknown;
|
||||
|
@ -31,7 +31,7 @@ namespace Pinetime {
|
|||
uint8_t second = 0;
|
||||
|
||||
uint32_t previousSystickCounter = 0;
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> currentDateTime;
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace Pinetime {
|
|||
|
||||
DirtyValue<uint8_t> batteryPercentRemaining {0};
|
||||
DirtyValue<bool> bleState {false};
|
||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds>> currentDateTime;
|
||||
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
|
||||
DirtyValue<Pinetime::Version> version;
|
||||
|
||||
lv_style_t* labelStyle;
|
||||
|
|
Loading…
Reference in a new issue