[time] Fixed web TCT issues. Added getDefaultLocale api to get region format of vconf...
authorHyunjin Park <hj.na.park@samsung.com>
Tue, 11 Aug 2015 01:16:53 +0000 (10:16 +0900)
committerHyunjin Park <hj.na.park@samsung.com>
Tue, 11 Aug 2015 01:58:06 +0000 (10:58 +0900)
- from http://slp-info.sec.samsung.net/gerrit/#/c/2663854/

Web TCT - Time : 100% passed

Change-Id: I398070a2c6a84c679c0822949daad647d4a96101

src/time/time_instance.cc
src/time/time_instance.h

index 9f75c23..ddf6255 100644 (file)
@@ -423,14 +423,47 @@ void TimeInstance::TimeGetDateFormat(const JsonValue& args, JsonObject& out) {
   ReportSuccess(JsonValue(result), out);
 }
 
+Locale* TimeInstance::getDefaultLocale() {
+   char *tempstr = vconf_get_str(VCONFKEY_REGIONFORMAT);
+   if (NULL == tempstr){
+        return NULL;
+      }
+
+   Locale *defaultLocale = NULL;
+
+   char *str_region = NULL;
+   char* p = strchr(tempstr, '.');
+   int len = strlen(tempstr) - strlen(".UTF-8");
+   if (p && len > 0) {
+          str_region = strndup(tempstr, len); //.UTF8 => 5
+          defaultLocale = new Locale(str_region);
+   }
+
+   free(tempstr);
+   free(str_region);
+
+   if (defaultLocale) {
+       if (defaultLocale->isBogus()) {
+           delete defaultLocale;
+           defaultLocale = NULL;
+       }
+   }
+
+   return defaultLocale;
+}
+
 UnicodeString TimeInstance::getDateTimeFormat(DateTimeFormatType type,
                                               bool bLocale) {
   LoggerD("Entered");
+  LoggerD("bLocale %d", bLocale);
 
   UErrorCode ec = U_ZERO_ERROR;
+  Locale *defaultLocale = getDefaultLocale();
   std::unique_ptr<DateTimePatternGenerator> dateTimepattern(
       DateTimePatternGenerator::createInstance(
-          (bLocale ? Locale::getDefault() : Locale::getEnglish()), ec));
+          ((bLocale && defaultLocale) ? *defaultLocale : Locale::getEnglish()), ec));
+
+  delete defaultLocale;
 
   if (U_FAILURE(ec)) {
     LoggerE("Failed to create Calendar instance");
index 6cb1e1e..3c5ffa9 100644 (file)
@@ -50,6 +50,7 @@ class TimeInstance : public common::ParsedInstance {
   void TimeUnsetTimezoneChangeListener(const JsonValue& args, JsonObject& out);
   void TimeGetMsUTC(const JsonValue& args, JsonObject& out);
 
+  Locale* getDefaultLocale();
   UnicodeString getDateTimeFormat(DateTimeFormatType type, bool bLocale);
   bool toStringByFormat(const JsonValue& args, JsonValue& out,
                         DateTimeFormatType format);