M module-apps/application-calendar/data/dateCommon.hpp => module-apps/application-calendar/data/dateCommon.hpp +9 -7
@@ 5,9 5,10 @@
#define DATECOMMON_H
#include <date/date.h>
-#include <time/DateAndTimeSettings.hpp>
#include <time/time_conversion_factory.hpp>
#include <Utils.hpp>
+#include <service-time/api/TimeSettingsApi.hpp>
+
#include <random>
using Clock = std::chrono::system_clock;
@@ 260,7 261,7 @@ inline std::string TimePointToLocalizedDateString(const TimePoint &tp, const std
{
using namespace utils::time;
auto time = TimePointToTimeT(tp);
- auto timestamp = createTimestamp(TimestampType::Date, time);
+ auto timestamp = TimestampFactory().createTimestamp(TimestampType::Date, time);
return timestamp->str(format);
}
@@ 268,14 269,15 @@ inline std::string TimePointToLocalizedTimeString(const TimePoint &tp, const std
{
using namespace utils::time;
auto time = TimePointToTimeT(tp);
- auto timestamp = createTimestamp(TimestampType::Time, time);
+
+ auto timestamp = TimestampFactory().createTimestamp(TimestampType::Time, time);
return timestamp->str(format);
}
inline std::string TimePointToLocalizedHourMinString(const TimePoint &tp)
{
- return utils::dateAndTimeSettings.isTimeFormat12() ? TimePointToLocalizedTimeString(tp, "%I:%M")
- : TimePointToLocalizedTimeString(tp, "%H:%M");
+ return stm::api::isTimeFormat12h() ? TimePointToLocalizedTimeString(tp, "%I:%M")
+ : TimePointToLocalizedTimeString(tp, "%H:%M");
}
inline TimePoint TimePointFromString(const char *s1)
@@ 324,8 326,8 @@ inline std::string TimePointToHourString12H(const TimePoint &tp)
inline std::string TimePointToLocalizedHourString(const TimePoint &tp)
{
- return utils::dateAndTimeSettings.isTimeFormat12() ? TimePointToLocalizedTimeString(tp, "%I")
- : TimePointToLocalizedTimeString(tp, "%H");
+ return stm::api::isTimeFormat12h() ? TimePointToLocalizedTimeString(tp, "%I")
+ : TimePointToLocalizedTimeString(tp, "%H");
}
inline std::string TimePointToHourString24H(const TimePoint &tp)
M module-apps/application-calllog/CalllogModel.cpp => module-apps/application-calllog/CalllogModel.cpp +0 -1
@@ 8,7 8,6 @@
#include "data/CallLogInternals.hpp"
#include "data/CallLogSwitchData.hpp"
#include "widgets/CalllogItem.hpp"
-#include <time/DateAndTimeSettings.hpp>
#include <service-appmgr/Controller.hpp>
#include "application-call/data/CallSwitchData.hpp"
M module-apps/application-calllog/widgets/CalllogItem.cpp => module-apps/application-calllog/widgets/CalllogItem.cpp +1 -1
@@ 75,7 75,7 @@ namespace gui
imageCallType[static_cast<uint32_t>(callType)]->setVisible(true);
using namespace utils::time;
- timestamp->setText(*createTimestamp(TimestampType::DateTime, call->date));
+ timestamp->setText(*TimestampFactory().createTimestamp(TimestampType::DateTime, call->date));
}
} /* namespace gui */
M module-apps/application-calllog/windows/CallLogDetailsWindow.cpp => module-apps/application-calllog/windows/CallLogDetailsWindow.cpp +2 -3
@@ 11,7 11,6 @@
#include <application-calllog/data/CallLogInternals.hpp>
#include <application-calllog/data/CallLogSwitchData.hpp>
#include <application-calllog/windows/CallLogOptionsWindow.hpp>
-#include <time/DateAndTimeSettings.hpp>
#include <widgets/TextWithIconsWidget.hpp>
#include <widgets/ActiveIconFactory.hpp>
@@ 197,8 196,8 @@ namespace gui
{
Expects(dateDay != nullptr && dateDate != nullptr);
using namespace utils::time;
- auto date = createTimestamp(TimestampType::Date, record.date);
- auto time = createTimestamp(TimestampType::Time, record.date);
+ auto date = TimestampFactory().createTimestamp(TimestampType::Date, record.date);
+ auto time = TimestampFactory().createTimestamp(TimestampType::Time, record.date);
dateDay->setText(date->day() + ",");
M module-apps/application-desktop/windows/DesktopMainWindow.cpp => module-apps/application-desktop/windows/DesktopMainWindow.cpp +2 -2
@@ 243,8 243,8 @@ namespace gui
{
using namespace utils::time;
auto ret = AppWindow::updateTime();
- auto clock = createTimestamp(TimestampType::Clock, std::time(nullptr));
- auto date = createTimestamp(TimestampType::DateText, std::time(nullptr));
+ auto clock = TimestampFactory().createTimestamp(TimestampType::Clock, std::time(nullptr));
+ auto date = TimestampFactory().createTimestamp(TimestampType::DateText, std::time(nullptr));
if (time != nullptr) {
time->setText(clock->str());
}
M module-apps/application-messages/models/ThreadsSearchResultsModel.cpp => module-apps/application-messages/models/ThreadsSearchResultsModel.cpp +1 -1
@@ 35,7 35,7 @@ namespace gui::model
{
using namespace utils::time;
ret->setContact(threadStruct->contact->getFormattedName());
- ret->setTimestamp(*createTimestamp(TimestampType::DateTime, threadStruct->thread->date));
+ ret->setTimestamp(*TimestampFactory().createTimestamp(TimestampType::DateTime, threadStruct->thread->date));
// The only thing that differs with ThreadModel actually - here show what was found
ret->setPreview(threadStruct->thread->snippet);
}
M module-apps/application-messages/widgets/SMSOutputWidget.cpp => module-apps/application-messages/widgets/SMSOutputWidget.cpp +1 -1
@@ 128,7 128,7 @@ namespace gui
timeLabel->activeItem = false;
timeLabel->setFont(style::window::font::verysmall);
using namespace utils::time;
- timeLabel->setText(*createTimestamp(TimestampType::Time, timestamp));
+ timeLabel->setText(*TimestampFactory().createTimestamp(TimestampType::Time, timestamp));
timeLabel->setVisible(false);
timeLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
timeLabel->setEdges(RectangleEdge::None);
M module-apps/application-messages/widgets/ThreadItem.cpp => module-apps/application-messages/widgets/ThreadItem.cpp +1 -1
@@ 51,7 51,7 @@ namespace gui
setContactName(getNumberImportance());
using namespace utils::time;
- timestamp->setText(*createTimestamp(TimestampType::DateTime, threadStruct->thread->date));
+ timestamp->setText(*TimestampFactory().createTimestamp(TimestampType::DateTime, threadStruct->thread->date));
setPreview();
}
M module-apps/application-notes/widgets/NotesItem.cpp => module-apps/application-notes/widgets/NotesItem.cpp +1 -1
@@ 57,7 57,7 @@ namespace gui
void NotesItem::setDateText(std::uint32_t timestamp)
{
using namespace utils::time;
- auto dt = createTimestamp(TimestampType::DateTime, timestamp);
+ auto dt = TimestampFactory().createTimestamp(TimestampType::DateTime, timestamp);
date->setText(*dt);
}
M module-apps/application-notes/windows/NotePreviewWindow.cpp => module-apps/application-notes/windows/NotePreviewWindow.cpp +1 -1
@@ 94,7 94,7 @@ namespace app::notes
void NotePreviewWindow::setEditDateText(std::uint32_t timestamp)
{
using namespace utils::time;
- auto dateTime = createTimestamp(TimestampType::DateTime, timestamp);
+ auto dateTime = TimestampFactory().createTimestamp(TimestampType::DateTime, timestamp);
auto dt = dynamic_cast<DateTime *>(dateTime.get());
if (dt == nullptr) {
return;
M module-apps/application-settings-new/CMakeLists.txt => module-apps/application-settings-new/CMakeLists.txt +2 -0
@@ 120,4 120,6 @@ target_link_libraries(${PROJECT_NAME}
PUBLIC
service-bluetooth
eventstore
+ PRIVATE
+ service-time-api
)
M module-apps/application-settings-new/models/DateAndTimeModel.cpp => module-apps/application-settings-new/models/DateAndTimeModel.cpp +0 -1
@@ 6,7 6,6 @@
#include "DateAndTimeModel.hpp"
#include <ListView.hpp>
#include <apps-common/widgets/DateAndTimeStyle.hpp>
-#include <time/DateAndTimeSettings.hpp>
DateAndTimeModel::DateAndTimeModel(app::Application *application) : app(application)
{}
M module-apps/application-settings-new/models/FromTimeToTimeModel.cpp => module-apps/application-settings-new/models/FromTimeToTimeModel.cpp +0 -1
@@ 5,7 5,6 @@
#include <application-settings-new/widgets/SettingsDateItem.hpp>
#include <application-settings-new/widgets/SettingsTimeItem.hpp>
#include <ListView.hpp>
-#include <time/DateAndTimeSettings.hpp>
#include <widgets/DateAndTimeStyle.hpp>
FromTimeToTimeModel::FromTimeToTimeModel(app::Application *application) : app(application)
M module-apps/application-settings-new/windows/DateAndTimeMainWindow.cpp => module-apps/application-settings-new/windows/DateAndTimeMainWindow.cpp +18 -10
@@ 4,9 4,10 @@
#include "application-settings-new/ApplicationSettings.hpp"
#include "DateAndTimeMainWindow.hpp"
#include "module-apps/application-desktop/windows/Names.hpp"
-#include <time/DateAndTimeSettings.hpp>
#include "OptionSetting.hpp"
-#include "service-appmgr/Controller.hpp"
+#include <service-time/service-time/TimeMessage.hpp>
+#include <service-time/Constants.hpp>
+#include <service-time/api/TimeSettingsApi.hpp>
namespace gui
{
@@ 14,10 15,11 @@ namespace gui
: BaseSettingsWindow(app, std::move(name))
{
setTitle(utils::translate("app_settings_date_and_time"));
- automaticDateAndTimeIsOn = utils::dateAndTimeSettings.isAutomaticDateAndTimeOn();
- automaticTimeZoneIsOn = utils::dateAndTimeSettings.isAutomaticTimeZoneOn();
- timeFormat = utils::dateAndTimeSettings.getTimeFormat();
- dateFormat = utils::dateAndTimeSettings.getDateFormat();
+
+ automaticDateAndTimeIsOn = stm::api::isAutomaticDateAndTime();
+ automaticTimeZoneIsOn = stm::api::isAutomaticTimezone();
+ timeFormat = stm::api::timeFormat();
+ dateFormat = stm::api::dateFormat();
changeDateAndTimeWindow = window::name::change_date_and_time;
}
@@ 47,7 49,9 @@ namespace gui
utils::translate("app_settings_date_and_time_automatic_date_and_time"),
[=](Item &item) {
automaticDateAndTimeIsOn = !automaticDateAndTimeIsOn;
- app::manager::Controller::changeAutomaticDateAndTimeIsOn(application, automaticDateAndTimeIsOn);
+ application->bus.sendUnicast(
+ std::make_shared<stm::message::SetAutomaticDateAndTimeRequest>(automaticDateAndTimeIsOn),
+ service::name::service_time);
refreshOptionsList();
return true;
},
@@ 65,7 69,9 @@ namespace gui
utils::translate("app_settings_date_and_time_automatic_time_zone"),
[=](Item &item) {
automaticTimeZoneIsOn = !automaticTimeZoneIsOn;
- app::manager::Controller::changeAutomaticTimeZoneIsOn(application, automaticTimeZoneIsOn);
+ application->bus.sendUnicast(
+ std::make_shared<stm::message::SetAutomaticTimezoneRequest>(automaticDateAndTimeIsOn),
+ service::name::service_time);
refreshOptionsList();
return true;
},
@@ 85,7 91,8 @@ namespace gui
timeFormat = (timeFormat == utils::time::Locale::TimeFormat::FormatTime12H)
? utils::time::Locale::TimeFormat::FormatTime24H
: utils::time::Locale::TimeFormat::FormatTime12H;
- app::manager::Controller::changeTimeFormat(application, timeFormat);
+ application->bus.sendUnicast(std::make_shared<stm::message::SetTimeFormatRequest>(timeFormat),
+ service::name::service_time);
refreshOptionsList();
return true;
},
@@ 98,7 105,8 @@ namespace gui
dateFormat = (dateFormat == utils::time::Locale::DateFormat::DD_MM_YYYY)
? utils::time::Locale::DateFormat::MM_DD_YYYY
: utils::time::Locale::DateFormat::DD_MM_YYYY;
- app::manager::Controller::changeDateFormat(application, dateFormat);
+ application->bus.sendUnicast(std::make_shared<stm::message::SetDateFormatRequest>(dateFormat),
+ service::name::service_time);
refreshOptionsList();
return true;
},
M module-apps/apps-common/Application.cpp => module-apps/apps-common/Application.cpp +0 -1
@@ 37,7 37,6 @@
#include <service-gui/Common.hpp>
#include <module-utils/Utils.hpp>
#include <service-db/agents/settings/SystemSettings.hpp>
-#include <time/DateAndTimeSettings.hpp>
#include <service-audio/AudioServiceAPI.hpp> // for GetOutputVolume
#include <popups/VolumeWindow.hpp>
M => +2 -2
@@ 147,8 147,8 @@ namespace gui
{
using namespace utils::time;
auto ret = AppWindow::updateTime();
auto clock = createTimestamp(TimestampType::Clock, std::time(nullptr));
auto date = createTimestamp(TimestampType::DateText, std::time(nullptr));
auto clock = TimestampFactory().createTimestamp(TimestampType::Clock, std::time(nullptr));
auto date = TimestampFactory().createTimestamp(TimestampType::DateText, std::time(nullptr));
if (time != nullptr) {
time->setText(clock->str());
}
M module-apps/apps-common/widgets/TimeWidget.cpp => module-apps/apps-common/widgets/TimeWidget.cpp +1 -1
@@ 19,7 19,7 @@ namespace gui
Type type,
std::function<void(const UTF8 &text)> bottomBarTemporaryMode,
std::function<void()> bottomBarRestoreFromTemporaryMode)
- : VBox(parent), mode24H{!utils::dateAndTimeSettings.isTimeFormat12()}, type{type},
+ : VBox(parent), mode24H{!stm::api::isTimeFormat12h()}, type{type},
bottomBarTemporaryMode(std::move(bottomBarTemporaryMode)),
bottomBarRestoreFromTemporaryMode(std::move(bottomBarRestoreFromTemporaryMode))
{
M module-apps/apps-common/windows/AppWindow.cpp => module-apps/apps-common/windows/AppWindow.cpp +0 -1
@@ 10,7 10,6 @@
#include <i18n/i18n.hpp>
#include <service-appmgr/Controller.hpp>
#include <service-audio/AudioServiceAPI.hpp>
-#include <time/DateAndTimeSettings.hpp>
using namespace style::header;
M module-gui/gui/widgets/status-bar/Time.cpp => module-gui/gui/widgets/status-bar/Time.cpp +1 -1
@@ 16,7 16,7 @@ namespace gui::status_bar
setFont(style::status_bar::time::font);
setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom));
using namespace utils::time;
- time = createTimestamp(TimestampType::Clock, std::time(nullptr));
+ time = TimestampFactory().createTimestamp(TimestampType::Clock, std::time(nullptr));
update();
}
M module-services/service-appmgr/Controller.cpp => module-services/service-appmgr/Controller.cpp +0 -24
@@ 84,30 84,6 @@ namespace app::manager
return sender->bus.sendUnicast(msg, ApplicationManager::ServiceName);
}
- auto Controller::changeAutomaticDateAndTimeIsOn(sys::Service *sender, bool isOn) -> bool
- {
- auto msg = std::make_shared<app::manager::AutomaticDateAndTimeIsOnChangeRequest>(isOn);
- return sender->bus.sendUnicast(std::move(msg), ApplicationManager::ServiceName);
- }
-
- auto Controller::changeAutomaticTimeZoneIsOn(sys::Service *sender, bool isOn) -> bool
- {
- auto msg = std::make_shared<app::manager::AutomaticTimeZoneIsOnChangeRequest>(isOn);
- return sender->bus.sendUnicast(std::move(msg), ApplicationManager::ServiceName);
- }
-
- auto Controller::changeTimeFormat(sys::Service *sender, utils::time::Locale::TimeFormat timeFormat) -> bool
- {
- auto msg = std::make_shared<app::manager::TimeFormatChangeRequest>(timeFormat);
- return sender->bus.sendUnicast(std::move(msg), ApplicationManager::ServiceName);
- }
-
- auto Controller::changeDateFormat(sys::Service *sender, utils::time::Locale::DateFormat dateFormat) -> bool
- {
- auto msg = std::make_shared<app::manager::DateFormatChangeRequest>(dateFormat);
- return sender->bus.sendUnicast(std::move(msg), ApplicationManager::ServiceName);
- }
-
auto Controller::preventBlockingDevice(sys::Service *sender) -> bool
{
auto msg = std::make_shared<app::manager::PreventBlockingRequest>(sender->GetName());
M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +1 -101
@@ 20,7 20,7 @@
#include <application-onboarding/ApplicationOnBoarding.hpp>
#include <application-onboarding/data/OnBoardingMessages.hpp>
#include <i18n/i18n.hpp>
-#include <log.hpp>
+#include <log/log.hpp>
#include <service-appmgr/messages/Message.hpp>
#include <service-evtmgr/EventManager.hpp>
#include <service-evtmgr/EVMessages.hpp>
@@ 35,7 35,6 @@
#include <limits>
#include <utility>
#include <module-utils/Utils.hpp>
-#include <time/DateAndTimeSettings.hpp>
#include <module-services/service-db/agents/settings/SystemSettings.hpp>
#include <service-appmgr/messages/DOMRequest.hpp>
#include <service-appmgr/messages/GetAllNotificationsRequest.hpp>
@@ 175,33 174,6 @@ namespace app::manager
[this](std::string value) { lockTimeChanged(std::move(value)); },
settings::SettingsScope::Global);
settings->registerValueChange(
- ::settings::SystemProperties::automaticDateAndTimeIsOn,
- [this](std::string value) {
- utils::dateAndTimeSettings.setAutomaticDateAndTimeOn(utils::getNumericValue<bool>(value));
- },
- ::settings::SettingsScope::Global);
- settings->registerValueChange(
- ::settings::SystemProperties::automaticTimeZoneIsOn,
- [this](std::string value) {
- utils::dateAndTimeSettings.setAutomaticTimeZoneOn(utils::getNumericValue<bool>(value));
- },
- ::settings::SettingsScope::Global);
- settings->registerValueChange(
- ::settings::SystemProperties::timeFormat,
- [this](std::string value) {
- utils::dateAndTimeSettings.setTimeFormat(
- static_cast<utils::time::Locale::TimeFormat>(utils::getNumericValue<unsigned int>(value)));
- },
- ::settings::SettingsScope::Global);
- settings->registerValueChange(
- ::settings::SystemProperties::dateFormat,
- [this](std::string value) {
- utils::dateAndTimeSettings.setDateFormat(
- static_cast<utils::time::Locale::DateFormat>(utils::getNumericValue<unsigned int>(value)));
- },
- ::settings::SettingsScope::Global);
-
- settings->registerValueChange(
::settings::KeypadLight::state,
[this](const std::string &value) {
const auto keypadLightState =
@@ 355,26 327,6 @@ namespace app::manager
handleInputLanguageChange(msg);
return sys::msgHandled();
});
- connect(typeid(AutomaticDateAndTimeIsOnChangeRequest), [this](sys::Message *request) {
- auto msg = static_cast<AutomaticDateAndTimeIsOnChangeRequest *>(request);
- handleAutomaticDateAndTimeChange(msg);
- return sys::msgHandled();
- });
- connect(typeid(AutomaticTimeZoneIsOnChangeRequest), [this](sys::Message *request) {
- auto msg = static_cast<AutomaticTimeZoneIsOnChangeRequest *>(request);
- handleAutomaticTimeZoneChange(msg);
- return sys::msgHandled();
- });
- connect(typeid(TimeFormatChangeRequest), [this](sys::Message *request) {
- auto msg = static_cast<TimeFormatChangeRequest *>(request);
- handleTimeFormatChange(msg);
- return sys::msgHandled();
- });
- connect(typeid(DateFormatChangeRequest), [this](sys::Message *request) {
- auto msg = static_cast<DateFormatChangeRequest *>(request);
- handleDateFormatChange(msg);
- return sys::msgHandled();
- });
connect(typeid(ShutdownRequest), [this](sys::Message *) {
closeApplications();
return std::make_shared<sys::ResponseMessage>();
@@ 1053,58 1005,6 @@ namespace app::manager
return true;
}
- auto ApplicationManager::handleAutomaticDateAndTimeChange(AutomaticDateAndTimeIsOnChangeRequest *msg) -> bool
- {
- if (utils::dateAndTimeSettings.isAutomaticDateAndTimeOn() == msg->isOn) {
- LOG_WARN("The selected value is already set. Ignore.");
- return false;
- }
- settings->setValue(settings::SystemProperties::automaticDateAndTimeIsOn,
- std::to_string(msg->isOn),
- settings::SettingsScope::Global);
- utils::dateAndTimeSettings.setAutomaticDateAndTimeOn(msg->isOn);
- return true;
- }
-
- auto ApplicationManager::handleAutomaticTimeZoneChange(AutomaticTimeZoneIsOnChangeRequest *msg) -> bool
- {
- if (utils::dateAndTimeSettings.isAutomaticTimeZoneOn() == msg->isOn) {
- LOG_WARN("The selected value is already set. Ignore.");
- return false;
- }
- settings->setValue(settings::SystemProperties::automaticTimeZoneIsOn,
- std::to_string(msg->isOn),
- settings::SettingsScope::Global);
- utils::dateAndTimeSettings.setAutomaticTimeZoneOn(msg->isOn);
- return true;
- }
-
- auto ApplicationManager::handleTimeFormatChange(TimeFormatChangeRequest *msg) -> bool
- {
- if (utils::dateAndTimeSettings.getTimeFormat() == msg->timeFormat) {
- LOG_WARN("The selected value is already set. Ignore.");
- return false;
- }
- settings->setValue(settings::SystemProperties::timeFormat,
- std::to_string(static_cast<unsigned>(msg->timeFormat)),
- settings::SettingsScope::Global);
- utils::dateAndTimeSettings.setTimeFormat(msg->timeFormat);
- return true;
- }
-
- auto ApplicationManager::handleDateFormatChange(DateFormatChangeRequest *msg) -> bool
- {
- if (utils::dateAndTimeSettings.getDateFormat() == msg->dateFormat) {
- LOG_WARN("The selected value is already set. Ignore.");
- return false;
- }
- settings->setValue(settings::SystemProperties::dateFormat,
- std::to_string(static_cast<unsigned>(msg->dateFormat)),
- settings::SettingsScope::Global);
- utils::dateAndTimeSettings.setDateFormat(msg->dateFormat);
- return true;
- }
-
auto ApplicationManager::handleSetOsUpdateVersionChange(SetOsUpdateVersion *msg) -> bool
{
LOG_DEBUG("[ApplicationManager::handleSetOsUpdateVersionChange] value ....");
D module-services/service-appmgr/service-appmgr/messages/DateAndTimeChangeRequest.hpp => module-services/service-appmgr/service-appmgr/messages/DateAndTimeChangeRequest.hpp +0 -45
@@ 1,45 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#pragma once
-
-#include "BaseMessage.hpp"
-#include <time/time_locale.hpp>
-
-namespace app::manager
-{
- class DateAndTimeChangeRequest : public sys::DataMessage
- {};
-
- class AutomaticDateAndTimeIsOnChangeRequest : public DateAndTimeChangeRequest
- {
- public:
- AutomaticDateAndTimeIsOnChangeRequest(bool isOn) : isOn(isOn)
- {}
- bool isOn;
- };
-
- class AutomaticTimeZoneIsOnChangeRequest : public DateAndTimeChangeRequest
- {
- public:
- AutomaticTimeZoneIsOnChangeRequest(bool isOn) : isOn(isOn)
- {}
- bool isOn;
- };
-
- class TimeFormatChangeRequest : public DateAndTimeChangeRequest
- {
- public:
- TimeFormatChangeRequest(utils::time::Locale::TimeFormat timeFormat) : timeFormat(timeFormat)
- {}
- utils::time::Locale::TimeFormat timeFormat;
- };
-
- class DateFormatChangeRequest : public DateAndTimeChangeRequest
- {
- public:
- DateFormatChangeRequest(utils::time::Locale::DateFormat dateFormat) : dateFormat(dateFormat)
- {}
- utils::time::Locale::DateFormat dateFormat;
- };
-} // namespace app::manager
M module-services/service-appmgr/service-appmgr/messages/Message.hpp => module-services/service-appmgr/service-appmgr/messages/Message.hpp +0 -1
@@ 19,6 19,5 @@
#include "ShutdownRequest.hpp"
#include "GetCurrentDisplayLanguageRequest.hpp"
#include "GetCurrentDisplayLanguageResponse.hpp"
-#include "DateAndTimeChangeRequest.hpp"
#include "UpdateInProgress.hpp"
#include "SetOsUpdateVersion.hpp"
M module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp => module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +0 -4
@@ 142,10 142,6 @@ namespace app::manager
auto handleInitApplication(ApplicationInitialised *msg) -> bool;
auto handleDisplayLanguageChange(DisplayLanguageChangeRequest *msg) -> bool;
auto handleInputLanguageChange(InputLanguageChangeRequest *msg) -> bool;
- auto handleAutomaticDateAndTimeChange(AutomaticDateAndTimeIsOnChangeRequest *msg) -> bool;
- auto handleAutomaticTimeZoneChange(AutomaticTimeZoneIsOnChangeRequest *msg) -> bool;
- auto handleTimeFormatChange(TimeFormatChangeRequest *msg) -> bool;
- auto handleDateFormatChange(DateFormatChangeRequest *msg) -> bool;
auto handleSetOsUpdateVersionChange(SetOsUpdateVersion *msg) -> bool;
auto handleDBResponse(db::QueryResponse *msg) -> bool;
auto handlePowerSavingModeInit() -> bool;
M module-services/service-time/CMakeLists.txt => module-services/service-time/CMakeLists.txt +5 -0
@@ 8,6 8,7 @@ set(SOURCES
TimezoneHandler.cpp
timeEvents/TimeEvents.cpp
timeEvents/CalendarTimeEvents.cpp
+ internal/StaticData.cpp
)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
@@ 19,10 20,14 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE
+ time
+ service-time-api
module-sys
module-apps
)
+add_subdirectory(api)
+
if (${ENABLE_TESTS})
add_subdirectory(tests)
endif ()
M module-services/service-time/ServiceTime.cpp => module-services/service-time/ServiceTime.cpp +108 -7
@@ 5,6 5,8 @@
#include "service-time/CalendarTimeEvents.hpp"
#include "service-time/TimeMessage.hpp"
#include "service-time/RTCCommand.hpp"
+#include <service-time/internal/StaticData.hpp>
+#include <service-time/TimeSettings.hpp>
#include <BaseInterface.hpp>
#include <Common/Query.hpp>
@@ 14,7 16,10 @@
#include <service-db/DBNotificationMessage.hpp>
#include <service-db/QueryMessage.hpp>
#include <service-cellular/service-cellular/CellularMessage.hpp>
+#include <service-cellular/service-cellular/ServiceCellular.hpp>
+#include <module-utils/Utils.hpp>
#include <time/time_constants.hpp>
+#include <time/time_conversion_factory.hpp>
#include <memory>
#include <utility>
@@ 37,6 42,13 @@ namespace stm
sys::ReturnCodes ServiceTime::InitHandler()
{
+ settings = std::make_unique<settings::Settings>();
+ settings->init(::service::ServiceProxy(shared_from_this()));
+
+ initStaticData();
+ static TimeSettings timeSettings;
+ utils::time::TimestampFactory().init(&timeSettings);
+
registerMessageHandlers();
return sys::ReturnCodes::Success;
@@ 124,16 136,105 @@ namespace stm
{
connect(typeid(CellularTimeNotificationMessage), [&](sys::Message *request) -> sys::MessagePointer {
auto message = static_cast<CellularTimeNotificationMessage *>(request);
- timeManager->handleCellularTimeUpdate(
- message->getTime().value(),
- std::chrono::minutes{message->getTimeZoneOffset().value() / utils::time::secondsInMinute});
+ if (stm::api::isAutomaticDateAndTime()) {
+ timeManager->handleCellularTimeUpdate(
+ message->getTime().value(),
+ std::chrono::minutes{message->getTimeZoneOffset().value() / utils::time::secondsInMinute});
+ }
return std::make_shared<sys::ResponseMessage>();
});
- connect(typeid(stm::message::TimeChangeRequestMessage), [&](sys::Message *request) -> sys::MessagePointer {
- auto message = static_cast<stm::message::TimeChangeRequestMessage *>(request);
- timeManager->handleTimeChangeRequest(message->getTime());
- return std::make_shared<sys::ResponseMessage>();
+ connect(typeid(stm::message::SetAutomaticDateAndTimeRequest),
+ [&](sys::Message *request) -> sys::MessagePointer {
+ return handleSetAutomaticDateAndTimeRequest(request);
+ });
+
+ connect(typeid(stm::message::SetAutomaticTimezoneRequest), [&](sys::Message *request) -> sys::MessagePointer {
+ return handleSetAutomaticTimezoneRequest(request);
});
+
+ connect(typeid(stm::message::SetTimeFormatRequest),
+ [&](sys::Message *request) -> sys::MessagePointer { return handleSetTimeFormatRequest(request); });
+
+ connect(typeid(stm::message::SetDateFormatRequest),
+ [&](sys::Message *request) -> sys::MessagePointer { return handleSetDateFormatRequest(request); });
+ }
+ auto ServiceTime::handleSetAutomaticDateAndTimeRequest(sys::Message *request)
+ -> std::shared_ptr<sys::ResponseMessage>
+ {
+ auto message = static_cast<stm::message::SetAutomaticDateAndTimeRequest *>(request);
+ if (stm::api::isAutomaticDateAndTime() == message->getValue()) {
+ LOG_WARN("The selected value is already set. Ignore.");
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+ settings->setValue(settings::SystemProperties::automaticDateAndTimeIsOn,
+ std::to_string(message->getValue()),
+ settings::SettingsScope::AppLocal);
+ stm::internal::StaticData::get().setAutomaticDateAndTime(message->getValue());
+
+ bus.sendUnicast(std::make_shared<stm::message::AutomaticDateAndTimeChangedMessage>(message->getValue()),
+ ServiceCellular::serviceName);
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+
+ auto ServiceTime::handleSetAutomaticTimezoneRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>
+ {
+ auto message = static_cast<stm::message::SetAutomaticTimezoneRequest *>(request);
+ if (stm::api::isAutomaticTimezone() == message->getValue()) {
+ LOG_WARN("The selected value is already set. Ignore.");
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+ settings->setValue(settings::SystemProperties::automaticTimeZoneIsOn,
+ std::to_string(message->getValue()),
+ settings::SettingsScope::AppLocal);
+ stm::internal::StaticData::get().setAutomaticTimezoneOn(message->getValue());
+ return std::shared_ptr<sys::ResponseMessage>();
}
+
+ auto ServiceTime::handleSetTimeFormatRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>
+ {
+ auto message = static_cast<stm::message::SetTimeFormatRequest *>(request);
+ if (stm::api::timeFormat() == message->getTimeFormat()) {
+ LOG_WARN("The selected value is already set. Ignore.");
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+ settings->setValue(settings::SystemProperties::timeFormat,
+ std::to_string(static_cast<unsigned>(message->getTimeFormat())),
+ settings::SettingsScope::AppLocal);
+ stm::internal::StaticData::get().setTimeFormat(message->getTimeFormat());
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+
+ auto ServiceTime::handleSetDateFormatRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>
+ {
+ auto message = static_cast<stm::message::SetDateFormatRequest *>(request);
+ if (stm::api::dateFormat() == message->getDateFormat()) {
+ LOG_WARN("The selected value is already set. Ignore.");
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+ settings->setValue(settings::SystemProperties::dateFormat,
+ std::to_string(static_cast<unsigned>(message->getDateFormat())),
+ settings::SettingsScope::AppLocal);
+ stm::internal::StaticData::get().setDateFormat(message->getDateFormat());
+ return std::shared_ptr<sys::ResponseMessage>();
+ }
+
+ void ServiceTime::initStaticData()
+ {
+ stm::internal::StaticData::get().setAutomaticDateAndTime(utils::getNumericValue<bool>(settings->getValue(
+ ::settings::SystemProperties::automaticDateAndTimeIsOn, settings::SettingsScope::AppLocal)));
+ stm::internal::StaticData::get().setAutomaticTimezoneOn(utils::getNumericValue<bool>(settings->getValue(
+ ::settings::SystemProperties::automaticTimeZoneIsOn, settings::SettingsScope::AppLocal)));
+ auto dateFormat = magic_enum::enum_cast<utils::time::Locale::DateFormat>(utils::getNumericValue<unsigned int>(
+ settings->getValue(::settings::SystemProperties::dateFormat, settings::SettingsScope::AppLocal)));
+ if (dateFormat != std::nullopt) {
+ stm::internal::StaticData::get().setDateFormat(dateFormat.value());
+ }
+ auto timeFormat = magic_enum::enum_cast<utils::time::Locale::TimeFormat>(utils::getNumericValue<unsigned int>(
+ settings->getValue(::settings::SystemProperties::timeFormat, settings::SettingsScope::AppLocal)));
+ if (timeFormat != std::nullopt) {
+ stm::internal::StaticData::get().setTimeFormat(timeFormat.value());
+ }
+ }
+
} /* namespace stm */
M module-services/service-time/ServiceTime.hpp => module-services/service-time/ServiceTime.hpp +14 -0
@@ 20,6 20,11 @@
#include <functional>
#include <string> // for allocator, string
+namespace settings
+{
+ class Settings;
+}
+
namespace stm
{
class ServiceTime : public sys::Service
@@ 29,7 34,16 @@ namespace stm
CalendarTimeEvents calendarEvents;
std::unique_ptr<TimeManager> timeManager;
+
+ std::unique_ptr<settings::Settings> settings;
+
void registerMessageHandlers();
+ auto handleSetAutomaticDateAndTimeRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>;
+ auto handleSetAutomaticTimezoneRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>;
+ auto handleSetTimeFormatRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>;
+ auto handleSetDateFormatRequest(sys::Message *request) -> std::shared_ptr<sys::ResponseMessage>;
+
+ void initStaticData();
public:
ServiceTime();
A module-services/service-time/api/CMakeLists.txt => module-services/service-time/api/CMakeLists.txt +14 -0
@@ 0,0 1,14 @@
+add_library(service-time-api STATIC)
+
+target_sources(service-time-api
+ PRIVATE
+ TimeSettingsApi.cpp
+ PUBLIC
+ TimeSettingsApi.hpp
+ )
+
+target_link_libraries(service-time-api
+ PRIVATE
+ time
+ service-time
+ )
A module-services/service-time/api/TimeSettingsApi.cpp => module-services/service-time/api/TimeSettingsApi.cpp +34 -0
@@ 0,0 1,34 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "TimeSettingsApi.hpp"
+#include <internal/StaticData.hpp>
+
+#include <time/time_locale.hpp>
+
+namespace stm::api
+{
+ bool isAutomaticDateAndTime()
+ {
+ return stm::internal::StaticData::get().getAutomaticDateAndTime();
+ }
+
+ bool isAutomaticTimezone()
+ {
+ return stm::internal::StaticData::get().getAutomaticTimezone();
+ }
+
+ utils::time::Locale::DateFormat dateFormat()
+ {
+ return stm::internal::StaticData::get().getDateFormat();
+ }
+
+ utils::time::Locale::TimeFormat timeFormat()
+ {
+ return stm::internal::StaticData::get().getTimeFormat();
+ }
+ bool isTimeFormat12h()
+ {
+ return stm::internal::StaticData::get().getTimeFormat() == utils::time::Locale::TimeFormat::FormatTime12H;
+ }
+} // namespace stm::api<
\ No newline at end of file
A module-services/service-time/api/TimeSettingsApi.hpp => module-services/service-time/api/TimeSettingsApi.hpp +35 -0
@@ 0,0 1,35 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <time/time_locale.hpp>
+
+namespace stm::api
+{
+ /**
+ * Gets value corresponded to current Automatic Date and Time setting stored in DB
+ * @return actual setting value
+ */
+ bool isAutomaticDateAndTime();
+ /**
+ * Gets value corresponded to current Automatic Timezone stored in DB
+ * @return actual setting value
+ */
+ bool isAutomaticTimezone();
+ /**
+ * Gets value corresponded to current Time format stored in DB
+ * @return actual setting value
+ */
+ utils::time::Locale::DateFormat dateFormat();
+ /**
+ * Gets value corresponded to current Date format setting stored in DB
+ * @return actual setting value
+ */
+ utils::time::Locale::TimeFormat timeFormat();
+ /**
+ *It checks if there is 12h time format set
+ * @return true when 12h format is set, false when 24h format is set
+ */
+ bool isTimeFormat12h();
+} // namespace stm::api
A module-services/service-time/internal/StaticData.cpp => module-services/service-time/internal/StaticData.cpp +55 -0
@@ 0,0 1,55 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "StaticData.hpp"
+
+namespace stm::internal
+{
+
+ StaticData &StaticData::get()
+ {
+ static StaticData instance;
+ return instance;
+ }
+
+ void StaticData::setAutomaticDateAndTime(bool value)
+ {
+ isAutomaticDateAndTimeOn = value;
+ }
+
+ bool StaticData::getAutomaticDateAndTime() const noexcept
+ {
+ return isAutomaticDateAndTimeOn;
+ }
+
+ void StaticData::setAutomaticTimezoneOn(bool value)
+ {
+ isAutomaticTimezoneOn = value;
+ }
+
+ bool StaticData::getAutomaticTimezone() const noexcept
+ {
+ return isAutomaticTimezoneOn;
+ }
+
+ void StaticData::setDateFormat(utils::time::Locale::DateFormat format)
+ {
+ dateFormat = format;
+ }
+
+ utils::time::Locale::DateFormat StaticData::getDateFormat() const noexcept
+ {
+ return dateFormat;
+ }
+
+ void StaticData::setTimeFormat(utils::time::Locale::TimeFormat format)
+ {
+ timeFormat = format;
+ }
+
+ utils::time::Locale::TimeFormat StaticData::getTimeFormat() const noexcept
+ {
+ return timeFormat;
+ }
+
+} // namespace stm::internal<
\ No newline at end of file
A module-services/service-time/internal/StaticData.hpp => module-services/service-time/internal/StaticData.hpp +72 -0
@@ 0,0 1,72 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <module-utils/time/time/time_locale.hpp>
+
+namespace stm::internal
+{
+ /**
+ * @brief Static settings data
+ */
+ class StaticData
+ {
+ private:
+ bool isAutomaticDateAndTimeOn = false;
+ bool isAutomaticTimezoneOn = false;
+ utils::time::Locale::DateFormat dateFormat = utils::time::Locale::DateFormat::DD_MM_YYYY;
+ utils::time::Locale::TimeFormat timeFormat = utils::time::Locale::TimeFormat::FormatTime12H;
+
+ StaticData() = default;
+
+ public:
+ StaticData(const StaticData &) = delete;
+ StaticData &operator=(const StaticData &) = delete;
+ /**
+ * Gets instance of static data object
+ * @return instance of data object
+ */
+ static StaticData &get();
+ /**
+ * Sets value corresponded to current Automatic Date and Time setting
+ * @param value new setting value
+ */
+ void setAutomaticDateAndTime(bool value);
+ /**
+ * Gets value corresponded to current Automatic Date and Time setting
+ * @return actual setting value
+ */
+ [[nodiscard]] bool getAutomaticDateAndTime() const noexcept;
+ /**
+ * ASets value corresponded to current Automatic Timezone setting
+ * @param value new setting value
+ */
+ void setAutomaticTimezoneOn(bool value);
+ /**
+ * Gets value corresponded to current Automatic Timezone setting
+ * @return actual setting value
+ */
+ [[nodiscard]] bool getAutomaticTimezone() const noexcept;
+ /**
+ * Sets value corresponded to current Date format setting
+ * @param format new setting value
+ */
+ void setDateFormat(utils::time::Locale::DateFormat format);
+ /**
+ * Gets value corresponded to current Date format setting
+ * @return actual setting value
+ */
+ [[nodiscard]] utils::time::Locale::DateFormat getDateFormat() const noexcept;
+ /**
+ * Sets value corresponded to current Time format setting
+ * @param format new setting value
+ */
+ void setTimeFormat(utils::time::Locale::TimeFormat format);
+ /**
+ * Gets value corresponded to current Time format setting
+ * @return actual setting value
+ */
+ [[nodiscard]] utils::time::Locale::TimeFormat getTimeFormat() const noexcept;
+ };
+} // namespace stm::internal<
\ No newline at end of file
M module-services/service-time/service-time/TimeManager.hpp => module-services/service-time/service-time/TimeManager.hpp +1 -1
@@ 28,7 28,7 @@ class TimeManager
/**
* Handles time change request.
* @param time UTC time to set
- */
+ * **/
void handleTimeChangeRequest(const time_t &time);
private:
M module-services/service-time/service-time/TimeMessage.hpp => module-services/service-time/service-time/TimeMessage.hpp +72 -1
@@ 4,7 4,8 @@
#pragma once
#include <MessageType.hpp>
-#include <Service/Message.hpp>
+#include <module-sys/Service/Message.hpp>
+#include <time/time_locale.hpp>
class TimeMessage : public sys::DataMessage
{
@@ 111,4 112,74 @@ namespace stm::message
private:
time_t time;
};
+
+ class SetAutomaticDateAndTimeRequest : public sys::DataMessage
+ {
+ public:
+ explicit SetAutomaticDateAndTimeRequest(const bool value)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), value(value){};
+ auto getValue() const -> bool
+ {
+ return value;
+ }
+
+ private:
+ bool value;
+ };
+
+ class AutomaticDateAndTimeChangedMessage : public sys::DataMessage
+ {
+ public:
+ explicit AutomaticDateAndTimeChangedMessage(const bool value)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), value(value){};
+ auto getValue() const -> bool
+ {
+ return value;
+ }
+
+ private:
+ bool value;
+ };
+
+ class SetAutomaticTimezoneRequest : public sys::DataMessage
+ {
+ public:
+ explicit SetAutomaticTimezoneRequest(const bool value)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), value(value){};
+ auto getValue() const -> bool
+ {
+ return value;
+ }
+
+ private:
+ bool value;
+ };
+
+ class SetTimeFormatRequest : public sys::DataMessage
+ {
+ public:
+ explicit SetTimeFormatRequest(const utils::time::Locale::TimeFormat timeFormat)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), timeFormat(timeFormat){};
+ auto getTimeFormat() const -> utils::time::Locale::TimeFormat
+ {
+ return timeFormat;
+ };
+
+ private:
+ utils::time::Locale::TimeFormat timeFormat;
+ };
+
+ class SetDateFormatRequest : public sys::DataMessage
+ {
+ public:
+ explicit SetDateFormatRequest(const utils::time::Locale::DateFormat dateFormat)
+ : sys::DataMessage(MessageType::MessageTypeUninitialized), dateFormat(dateFormat){};
+ auto getDateFormat() const -> utils::time::Locale::DateFormat
+ {
+ return dateFormat;
+ };
+
+ private:
+ utils::time::Locale::DateFormat dateFormat;
+ };
} // namespace stm::message
A module-services/service-time/service-time/TimeSettings.hpp => module-services/service-time/service-time/TimeSettings.hpp +19 -0
@@ 0,0 1,19 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <time/time_conversion.hpp>
+
+class TimeSettings : public utils::time::TimeSettingsInterface
+{
+ public:
+ bool isTimeFormat12h() const final
+ {
+ return stm::api::timeFormat() == utils::time::Locale::TimeFormat::FormatTime12H;
+ }
+ bool isDateFormatDDMM() const final
+ {
+ return stm::api::dateFormat() == utils::time::Locale::DateFormat::DD_MM_YYYY;
+ }
+};
M module-utils/time/CMakeLists.txt => module-utils/time/CMakeLists.txt +0 -1
@@ 13,7 13,6 @@ module_is_test_entity(time)
target_sources(time
PRIVATE
- time/DateAndTimeSettings.cpp
time/time_conversion.cpp
time/time_date_validation.cpp
time/TimeRangeParser.cpp
A module-utils/time/test/mock/TimeSettingsMock.hpp => module-utils/time/test/mock/TimeSettingsMock.hpp +19 -0
@@ 0,0 1,19 @@
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include "time/time_conversion.hpp"
+
+class BaseTimeSettings : public utils::time::TimeSettingsInterface
+{
+ public:
+ virtual bool isTimeFormat12h() const
+ {
+ return true;
+ };
+ virtual bool isDateFormatDDMM() const
+ {
+ return true;
+ };
+};<
\ No newline at end of file
M module-utils/time/test/unittest_time.cpp => module-utils/time/test/unittest_time.cpp +19 -0
@@ 10,6 10,8 @@
#include "time/time_conversion.hpp"
#include "time/time_locale.hpp"
+#include "time/time_conversion_factory.hpp"
+#include "mock/TimeSettingsMock.hpp"
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
@@ 681,3 683,20 @@ TEST_CASE("Duration - display")
REQUIRE(duration.str(Duration::DisplayedFormat::FixedH0M0S) == "48:03:04");
}
}
+TEST_CASE("Timestamp factory")
+{
+ SECTION("No setting provided")
+ {
+ auto timestamp = utils::time::TimestampFactory().createTimestamp(utils::time::TimestampType::Clock);
+
+ REQUIRE(typeid(*(timestamp.get())).name() == typeid(utils::time::Timestamp).name());
+ }
+ SECTION("Settings provided")
+ {
+ auto factory = utils::time::TimestampFactory();
+ factory.init(new BaseTimeSettings);
+ auto timestamp = factory.createTimestamp(utils::time::TimestampType::Clock);
+
+ REQUIRE(typeid(*(timestamp.get())).name() == typeid(utils::time::Clock).name());
+ }
+}
D module-utils/time/time/DateAndTimeSettings.cpp => module-utils/time/time/DateAndTimeSettings.cpp +0 -29
@@ 1,29 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include "DateAndTimeSettings.hpp"
-
-namespace utils
-{
- DateAndTimeSettings dateAndTimeSettings;
-
- void DateAndTimeSettings::setAutomaticDateAndTimeOn(bool value)
- {
- automaticDateAndTimeIsOn = value;
- }
-
- void DateAndTimeSettings::setAutomaticTimeZoneOn(bool value)
- {
- automaticTimeZoneIsOn = value;
- }
-
- void DateAndTimeSettings::setTimeFormat(time::Locale::TimeFormat format)
- {
- timeFormat = format;
- }
-
- void DateAndTimeSettings::setDateFormat(time::Locale::DateFormat format)
- {
- dateFormat = format;
- }
-} // namespace utils
D module-utils/time/time/DateAndTimeSettings.hpp => module-utils/time/time/DateAndTimeSettings.hpp +0 -45
@@ 1,45 0,0 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#pragma once
-
-#include <time/time_locale.hpp>
-
-namespace utils
-{
- class DateAndTimeSettings
- {
- public:
- [[nodiscard]] auto isAutomaticDateAndTimeOn() const noexcept -> bool
- {
- return automaticDateAndTimeIsOn;
- }
- [[nodiscard]] auto isAutomaticTimeZoneOn() const noexcept -> bool
- {
- return automaticTimeZoneIsOn;
- }
- [[nodiscard]] auto getTimeFormat() const noexcept -> time::Locale::TimeFormat
- {
- return timeFormat;
- }
- [[nodiscard]] auto getDateFormat() const noexcept -> time::Locale::DateFormat
- {
- return dateFormat;
- }
- [[nodiscard]] bool isTimeFormat12() const noexcept
- {
- return timeFormat == utils::time::Locale::TimeFormat::FormatTime12H;
- }
- void setAutomaticDateAndTimeOn(bool value);
- void setAutomaticTimeZoneOn(bool value);
- void setTimeFormat(time::Locale::TimeFormat format);
- void setDateFormat(time::Locale::DateFormat format);
-
- private:
- bool automaticDateAndTimeIsOn = false;
- bool automaticTimeZoneIsOn = false;
- time::Locale::TimeFormat timeFormat = time::Locale::defaultTimeFormat;
- time::Locale::DateFormat dateFormat = time::Locale::defaultDateFormat;
- };
- extern DateAndTimeSettings dateAndTimeSettings;
-} // namespace utils
M module-utils/time/time/time_conversion.cpp => module-utils/time/time/time_conversion.cpp +0 -1
@@ 17,7 17,6 @@
#include "i18n/i18n.hpp"
#include "time_locale.hpp"
-#include "DateAndTimeSettings.hpp"
#include <Utils.hpp>
#include <time/time_constants.hpp>
M module-utils/time/time/time_conversion_factory.cpp => module-utils/time/time/time_conversion_factory.cpp +10 -23
@@ 3,43 3,30 @@
#include "time_conversion_factory.hpp"
#include "time_conversion.hpp"
-#include "DateAndTimeSettings.hpp"
namespace utils::time
{
+ TimeSettingsInterface *TimestampFactory::timeSettings = nullptr;
- namespace
+ std::unique_ptr<Timestamp> TimestampFactory::createTimestamp(TimestampType type, time_t time)
{
- class TimeSettings : public TimeSettingsInterface
- {
- bool isTimeFormat12h() const final
- {
- return utils::dateAndTimeSettings.getTimeFormat() == Locale::TimeFormat::FormatTime12H;
- }
- bool isDateFormatDDMM() const final
- {
- return utils::dateAndTimeSettings.getDateFormat() == Locale::DateFormat::DD_MM_YYYY;
- }
- };
- } // namespace
-
- std::unique_ptr<Timestamp> createTimestamp(TimestampType type, time_t time)
- {
- static TimeSettings timeSettings;
+ if (timeSettings == nullptr) {
+ return std::make_unique<Timestamp>(time);
+ }
switch (type) {
case TimestampType::Timestamp:
return std::make_unique<Timestamp>(time);
case TimestampType::Date:
- return std::make_unique<Date>(timeSettings, time);
+ return std::make_unique<Date>(*timeSettings, time);
case TimestampType::DateText:
- return std::make_unique<DateText>(timeSettings, time);
+ return std::make_unique<DateText>(*timeSettings, time);
case TimestampType::Time:
- return std::make_unique<Time>(timeSettings, time);
+ return std::make_unique<Time>(*timeSettings, time);
case TimestampType::DateTime:
- return std::make_unique<DateTime>(timeSettings, time);
+ return std::make_unique<DateTime>(*timeSettings, time);
case TimestampType::Clock:
- return std::make_unique<Clock>(timeSettings, time);
+ return std::make_unique<Clock>(*timeSettings, time);
}
return std::make_unique<Timestamp>(time);
M module-utils/time/time/time_conversion_factory.hpp => module-utils/time/time/time_conversion_factory.hpp +12 -1
@@ 18,6 18,17 @@ namespace utils::time
Date, /// date
DateText, /// date in textual represnatation
};
+ class TimestampFactory
+ {
+ private:
+ static TimeSettingsInterface *timeSettings;
- std::unique_ptr<Timestamp> createTimestamp(TimestampType type, time_t time = 0);
+ public:
+ TimestampFactory() = default;
+ void init(TimeSettingsInterface *settings)
+ {
+ timeSettings = settings;
+ }
+ std::unique_ptr<Timestamp> createTimestamp(TimestampType type, time_t time = 0);
+ };
} // namespace utils::time