1 #include "GetDeviceTimeCommand.h"
3 #include <system_settings.h>
4 #include <utils_i18n.h>
10 GetDeviceTimeCommand::GetDeviceTimeCommand(
11 const ::aurum::ReqGetDeviceTime* request,
12 ::aurum::RspGetDeviceTime* response)
13 : mRequest{request}, mResponse{response}
17 class TizenLocaleTimeConverter {
19 static std::string convert(long long timestamp)
22 i18n_udatepg_h pattern_generator = NULL;
25 if (SYSTEM_SETTINGS_ERROR_NONE !=
26 system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY,
29 //dlog_print(DLOG_INFO, LOG_TAG, "Current Locale Country : %s\n", locale);
30 LOG_F(INFO, "%s", locale);
31 i18n_udatepg_create(locale, &pattern_generator);
33 if (!pattern_generator) return time;
35 i18n_uchar bestPattern[64] = {
38 char bestPatternString[64] = {
41 int bestPatternLength, len;
42 const char* custom_format = "EEE, MMM d, yyyy 'at' HH:mm:ss zzz";
43 i18n_uchar uch_custom_format[64];
45 i18n_ustring_copy_ua(uch_custom_format, custom_format);
46 len = i18n_ustring_get_length(uch_custom_format);
47 i18n_udatepg_get_best_pattern(pattern_generator, uch_custom_format, len,
48 bestPattern, 64, &bestPatternLength);
49 i18n_ustring_copy_au_n(bestPatternString, bestPattern, 64);
50 //dlog_print(DLOG_INFO, LOG_TAG, "BestPattern(char[]) : %s \n", bestPatternString);
51 i18n_udatepg_destroy(pattern_generator);
53 i18n_udate_format_h formatter_Current = NULL;
54 i18n_uchar formatted[64] = {
62 char* timezone_Current;
63 i18n_uchar utf16_timezone_Current[64] = {
67 if (SYSTEM_SETTINGS_ERROR_NONE !=
68 system_settings_get_value_string(
69 SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &timezone_Current))
72 i18n_ustring_copy_ua_n(utf16_timezone_Current, timezone_Current,
73 strlen(timezone_Current));
74 if (I18N_ERROR_NONE !=
75 i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, locale,
76 utf16_timezone_Current, -1, bestPattern, -1,
80 if (utf16_timezone_Current) {
81 date = (i18n_udate)((double)(timestamp / 1000.0));
82 i18n_udate_format_date(formatter_Current, date, formatted, 64, NULL,
84 i18n_ustring_copy_au_n(result, formatted, 64);
85 //dlog_print(DLOG_INFO, LOG_TAG, "Current Date : %s\n", result);
86 time = std::string{result};
87 LOG_F(INFO, "%s", result);
89 i18n_udate_destroy(formatter_Current);
94 ::grpc::Status GetDeviceTimeCommand::execute()
96 LOG_SCOPE_F(INFO, "GetDeviceTime --------------- ");
98 UiDevice* obj = UiDevice::getInstance(DeviceType::DEFAULT);
99 ::aurum::ReqGetDeviceTime_TimeType type = mRequest->type();
100 long long utcStampMs;
102 //if (type == ::aurum::ReqGetAttribute_RequestType::ReqGetAttribute_RequestType_VISIBLE)
105 case ::aurum::ReqGetDeviceTime_TimeType::ReqGetDeviceTime_TimeType_WALLCLOCK:
106 utcStampMs = obj->getSystemTime(TypeRequestType::WALLCLOCK);
107 mResponse->set_localedatetime(
108 TizenLocaleTimeConverter::convert(utcStampMs));
109 mResponse->set_timestamputc(utcStampMs);
112 case ::aurum::ReqGetDeviceTime_TimeType::ReqGetDeviceTime_TimeType_SYSTEM:
114 utcStampMs = obj->getSystemTime(TypeRequestType::MONOTONIC);
115 mResponse->set_timestamputc(utcStampMs);
119 mResponse->set_status(::aurum::RspStatus::OK);
120 return grpc::Status::OK;