From: Wonki Kim Date: Sat, 25 Apr 2020 03:55:33 +0000 (+0900) Subject: bootstrap: fix a GetDeviceTime Command bug X-Git-Tag: accepted/tizen/unified/20200427.031423^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=255d1e5547bf548ba4766573a581b9ff3a198163;p=platform%2Fcore%2Fuifw%2Faurum.git bootstrap: fix a GetDeviceTime Command bug getdevicecommand returns wrong datetime string because it calculates the string with wrong timestamp. Change-Id: Ibcc938d80caef52ea8968c9da5c46e09b85b48ed --- diff --git a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc index 61d58ec..f313311 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/GetDeviceTimeCommand.cc @@ -6,6 +6,7 @@ #include #include "UiDevice.h" +#include GetDeviceTimeCommand::GetDeviceTimeCommand( const ::aurum::ReqGetDeviceTime* request, @@ -16,78 +17,70 @@ GetDeviceTimeCommand::GetDeviceTimeCommand( class TizenLocaleTimeConverter { public: - static std::string convert(long long timestamp) + static std::string convert(long long timestamp, const char *pattern) { - std::string time; + if (timestamp < 0 || pattern == NULL) return ""; + + char *locale, *timezone; + i18n_udatepg_h pattern_generator = NULL; - char* locale; - - if (SYSTEM_SETTINGS_ERROR_NONE != - system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, - &locale)) - return time; - //dlog_print(DLOG_INFO, LOG_TAG, "Current Locale Country : %s\n", locale); - LOG_F(INFO, "%s", locale); + i18n_udate_format_h formatter = NULL; + + i18n_uchar timezone_i18[64] = {0,}; + i18n_uchar pattern_i18[64]= {0,}; + i18n_uchar best_pattern_i18[64]= {0,}; + i18n_uchar result_i18[64]= {0,}; + char result[64]= {0,}; + + int pattern_len, best_pattern_len, result_i18n_len; + + if (SYSTEM_SETTINGS_ERROR_NONE != system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, &locale)) + return ""; + + if (SYSTEM_SETTINGS_ERROR_NONE != system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &timezone)) { + if (locale) free(locale); + return ""; + } + i18n_udatepg_create(locale, &pattern_generator); - if (!pattern_generator) return time; - - i18n_uchar bestPattern[64] = { - 0, - }; - char bestPatternString[64] = { - 0, - }; - int bestPatternLength, len; - const char* custom_format = "EEE, MMM d, yyyy 'at' HH:mm:ss zzz"; - i18n_uchar uch_custom_format[64]; - - i18n_ustring_copy_ua(uch_custom_format, custom_format); - len = i18n_ustring_get_length(uch_custom_format); - i18n_udatepg_get_best_pattern(pattern_generator, uch_custom_format, len, - bestPattern, 64, &bestPatternLength); - i18n_ustring_copy_au_n(bestPatternString, bestPattern, 64); - //dlog_print(DLOG_INFO, LOG_TAG, "BestPattern(char[]) : %s \n", bestPatternString); + if (!pattern_generator) { + free (locale); + free (timezone); + return ""; + } + + i18n_ustring_copy_ua_n(pattern_i18, pattern, strlen(pattern)); + pattern_len = i18n_ustring_get_length(pattern_i18); + + i18n_udatepg_get_best_pattern(pattern_generator, + pattern_i18, pattern_len, + best_pattern_i18, 64, &best_pattern_len); + + i18n_ustring_copy_ua_n(timezone_i18, timezone, strlen(timezone)); + i18n_udatepg_destroy(pattern_generator); - i18n_udate_format_h formatter_Current = NULL; - i18n_uchar formatted[64] = { - 0, - }; - char result[64] = { - 0, - }; - int formattedLength; - i18n_udate date; - char* timezone_Current; - i18n_uchar utf16_timezone_Current[64] = { - 0, - }; - - if (SYSTEM_SETTINGS_ERROR_NONE != - system_settings_get_value_string( - SYSTEM_SETTINGS_KEY_LOCALE_TIMEZONE, &timezone_Current)) - return time; - - i18n_ustring_copy_ua_n(utf16_timezone_Current, timezone_Current, - strlen(timezone_Current)); if (I18N_ERROR_NONE != i18n_udate_create(I18N_UDATE_PATTERN, I18N_UDATE_PATTERN, locale, - utf16_timezone_Current, -1, bestPattern, -1, - &formatter_Current)) - return time; - - if (utf16_timezone_Current) { - date = (i18n_udate)((double)(timestamp / 1000.0)); - i18n_udate_format_date(formatter_Current, date, formatted, 64, NULL, - &formattedLength); - i18n_ustring_copy_au_n(result, formatted, 64); - //dlog_print(DLOG_INFO, LOG_TAG, "Current Date : %s\n", result); - time = std::string{result}; - LOG_F(INFO, "%s", result); + timezone_i18, -1, best_pattern_i18, -1, + &formatter)) { + free (locale); + free (timezone); + return ""; } - i18n_udate_destroy(formatter_Current); - return time; + + if (formatter) { + i18n_udate date = timestamp; + i18n_udate_format_date(formatter, date, result_i18, 64, NULL, &result_i18n_len); + i18n_ustring_copy_au_n(result , result_i18, 64); + i18n_udate_destroy(formatter); + return std::string{result}; + } + + free (locale); + free (timezone); + return ""; } }; @@ -99,13 +92,12 @@ public: ::aurum::ReqGetDeviceTime_TimeType type = mRequest->type(); long long utcStampMs; -//if (type == ::aurum::ReqGetAttribute_RequestType::ReqGetAttribute_RequestType_VISIBLE) - switch (type) { case ::aurum::ReqGetDeviceTime_TimeType::ReqGetDeviceTime_TimeType_WALLCLOCK: utcStampMs = obj->getSystemTime(TypeRequestType::WALLCLOCK); mResponse->set_localedatetime( - TizenLocaleTimeConverter::convert(utcStampMs)); + TizenLocaleTimeConverter::convert(utcStampMs, "EEE, MMM d, yyyy 'at' HH:mm:ss zzz").c_str() + ); mResponse->set_timestamputc(utcStampMs); break;