16 #include "LocalTime.h" 26 static constexpr std::string_view HoursMinutesFmt =
"%R";
27 static constexpr std::string_view LongSecondsFmt =
"%S %Z";
28 static constexpr std::string_view ShortSecondsFmt =
"%Z";
30 std::unique_ptr<cpp_local_time::LocalTime> mLocalTimeConvert{};
38 const std::time_put<char> &locale_time_put;
50 auto put_locale_time(std::stringstream &strm,
char fill,
const std::tm *tm,
const std::string_view &format) {
51 auto fmt = std::string{format};
53 throw std::runtime_error(
"Format must not be empty");
55 const char *fmtbeg = fmt.c_str();
56 const char *fmtend = fmtbeg + fmt.size();
57 return locale_time_put.put(strm, strm, fill, tm, fmtbeg, fmtend);
61 void updateTimeDisplay();
76 explicit TimeBox(std::shared_ptr<TimerTick> timerTick);
78 TimeBox(std::shared_ptr<TimerTick> timerTick,
bool seconds,
bool localTime =
false) :
TimeBox(std::move(timerTick)) {
83 TimeBox(std::shared_ptr<TimerTick> timerTick,
const char *timeZone,
bool seconds =
true) :
TimeBox(std::move(timerTick)) {
88 TimeBox(std::shared_ptr<TimerTick> timerTick,
const std::string &timeZone,
bool seconds =
true) :
TimeBox(std::move(timerTick)) {
93 static constexpr std::string_view
id =
"TimeBox";
94 std::string_view nodeId()
const noexcept
override {
116 static constexpr std::string_view LongDateFormat =
"%a %b %d, %Y";
117 static constexpr std::string_view ShortDateFormat =
"%a %b %d";
119 std::unique_ptr<cpp_local_time::LocalTime> mLocalTimeConvert{};
121 bool mDisplayYear{
true};
127 const std::time_put<char> &locale_time_put;
139 auto put_locale_time(std::stringstream &strm,
char fill,
const std::tm *tm,
const std::string_view &format) {
140 auto fmt = std::string{format};
142 throw std::runtime_error(
"Format must not be empty");
144 const char *fmtbeg = fmt.c_str();
145 const char *fmtend = fmtbeg + fmt.size();
146 return locale_time_put.put(strm, strm, fill, tm, fmtbeg, fmtend);
150 void updateDateDisplay();
165 explicit DateBox(std::shared_ptr<TimerTick> minutes);
167 DateBox(std::shared_ptr<TimerTick> timerTick,
bool year,
bool localTime =
false) :
DateBox(std::move(timerTick)) {
172 DateBox(std::shared_ptr<TimerTick> timerTick,
const char *timeZone,
bool year =
true) :
DateBox(std::move(timerTick)) {
177 DateBox(std::shared_ptr<TimerTick> timerTick,
const std::string &timeZone,
bool year =
true) :
DateBox(std::move(timerTick)) {
182 static constexpr std::string_view
id =
"DateBox";
183 std::string_view nodeId()
const noexcept
override {
205 bool mDisplaySecond{};
209 std::shared_ptr<TimerTick> mTick{};
226 explicit TimeDateBox(std::shared_ptr<TimerTick> tick);
228 TimeDateBox(std::shared_ptr<TimerTick> timerTick,
bool second,
bool year,
bool localTime =
false) :
TimeDateBox(std::move(timerTick)) {
230 mDisplaySecond = second;
234 TimeDateBox(std::shared_ptr<TimerTick> timerTick,
const char *timeZone,
bool second,
bool year =
true) :
TimeDateBox(std::move(timerTick)) {
236 mDisplaySecond = second;
240 TimeDateBox(std::shared_ptr<TimerTick> timerTick,
const std::string &timeZone,
bool second,
bool year =
true) :
TimeDateBox(std::move(timerTick)) {
242 mDisplaySecond = second;
246 static constexpr std::string_view
id =
"TimeDateBox";
247 std::string_view nodeId()
const noexcept
override {
auto put_locale_time(std::stringstream &strm, char fill, const std::tm *tm, const std::string_view &format)
A helper function to convert the system time to a localized time.
Definition: TimeBox.h:139
bool mLocalTime
If time zone is empty display local time if true.
Definition: TimeBox.h:34
TickProtocol::slot_type secondSlot
Receive time signals.
Definition: TimeBox.h:37
A Widget which manages contained Widgets.
Definition: Visual.h:697
std::shared_ptr< TimerTick > mTimerTick
The source of time signals.
Definition: TimeBox.h:32
bool mDisplaySeconds
Display seconds in time.
Definition: TimeBox.h:33
std::shared_ptr< Slot< Args... > > slot_type
Composed Slot type.
Definition: Signals.h:123
void draw(gm::Context &context, const Position< int > &containerPosition) override
Draw the TimeBox and contents.
Definition: TimeBox.cpp:52
std::string mTimeZone
The time zone if not empty.
Definition: TimeBox.h:35
Rectangle layout(gm::Context &context, const Rectangle &screenRect) override
Layout the TimeBox and contents.
Definition: TimeBox.cpp:56
Context
Definition: GraphicsModel.h:76
auto put_locale_time(std::stringstream &strm, char fill, const std::tm *tm, const std::string_view &format)
A helper function to convert the system time to a localized time.
Definition: TimeBox.h:50
Definition: TimeBox.h:203
A composite of a Position and a Size.
Definition: Types.h:307
Definition: TimeBox.h:114
ToDo: There is an issue that the initial scroll interaction is lost if the click/press lands on a Wid...
Definition: CelestialOverlay.cpp:13
Establish an intra-application signaling protocol.