2019-12-28 13:34:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-01-18 12:56:25 +00:00
|
|
|
#include <chrono>
|
2019-12-28 13:34:50 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2021-04-02 15:33:49 +00:00
|
|
|
namespace System {
|
|
|
|
class SystemTask;
|
|
|
|
}
|
2019-12-28 13:34:50 +00:00
|
|
|
namespace Controllers {
|
|
|
|
class DateTime {
|
2021-04-24 09:00:45 +00:00
|
|
|
public:
|
2021-04-18 17:28:14 +00:00
|
|
|
enum class Days : uint8_t { Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
|
|
|
|
enum class Months : uint8_t {
|
|
|
|
Unknown,
|
|
|
|
January,
|
|
|
|
February,
|
|
|
|
March,
|
|
|
|
April,
|
|
|
|
May,
|
|
|
|
June,
|
|
|
|
July,
|
|
|
|
August,
|
|
|
|
September,
|
|
|
|
October,
|
|
|
|
November,
|
|
|
|
December
|
|
|
|
};
|
2019-12-28 13:34:50 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
void 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);
|
|
|
|
void UpdateTime(uint32_t systickCounter);
|
|
|
|
uint16_t Year() const {
|
|
|
|
return year;
|
|
|
|
}
|
|
|
|
Months Month() const {
|
|
|
|
return month;
|
|
|
|
}
|
|
|
|
uint8_t Day() const {
|
|
|
|
return day;
|
|
|
|
}
|
|
|
|
Days DayOfWeek() const {
|
|
|
|
return dayOfWeek;
|
|
|
|
}
|
|
|
|
uint8_t Hours() const {
|
|
|
|
return hour;
|
|
|
|
}
|
|
|
|
uint8_t Minutes() const {
|
|
|
|
return minute;
|
|
|
|
}
|
|
|
|
uint8_t Seconds() const {
|
|
|
|
return second;
|
|
|
|
}
|
2020-01-18 17:17:52 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
const char* MonthShortToString();
|
|
|
|
const char* MonthShortToStringLow();
|
|
|
|
const char* MonthsToStringLow();
|
|
|
|
const char* DayOfWeekToString();
|
|
|
|
const char* DayOfWeekShortToString();
|
|
|
|
const char* DayOfWeekToStringLow();
|
|
|
|
const char* DayOfWeekShortToStringLow();
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
|
|
|
|
return currentDateTime;
|
|
|
|
}
|
|
|
|
std::chrono::seconds Uptime() const {
|
|
|
|
return uptime;
|
|
|
|
}
|
2020-01-18 12:56:25 +00:00
|
|
|
|
2021-06-06 13:56:03 +00:00
|
|
|
void Register(System::SystemTask* systemTask);
|
|
|
|
|
2021-04-24 09:00:45 +00:00
|
|
|
private:
|
2021-04-18 17:28:14 +00:00
|
|
|
uint16_t year = 0;
|
|
|
|
Months month = Months::Unknown;
|
|
|
|
uint8_t day = 0;
|
|
|
|
Days dayOfWeek = Days::Unknown;
|
|
|
|
uint8_t hour = 0;
|
|
|
|
uint8_t minute = 0;
|
|
|
|
uint8_t second = 0;
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
uint32_t previousSystickCounter = 0;
|
|
|
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> currentDateTime;
|
|
|
|
std::chrono::seconds uptime {0};
|
2021-04-02 15:33:49 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
bool isMidnightAlreadyNotified = false;
|
2021-06-06 13:56:03 +00:00
|
|
|
System::SystemTask* systemTask = nullptr;
|
2021-02-24 19:40:24 +00:00
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
static char const* DaysString[];
|
|
|
|
static char const* DaysStringShort[];
|
|
|
|
static char const* DaysStringLow[];
|
|
|
|
static char const* DaysStringShortLow[];
|
|
|
|
static char const* MonthsString[];
|
|
|
|
static char const* MonthsStringLow[];
|
|
|
|
static char const* MonthsLow[];
|
2019-12-28 13:34:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|