Fixed deprecated API using (JIRA task #917)
authorAdam Szczerbiak <a.szczerbiak@samsung.com>
Tue, 12 Jan 2016 10:50:14 +0000 (11:50 +0100)
committerAdam Szczerbiak <a.szczerbiak@samsung.com>
Tue, 12 Jan 2016 12:53:05 +0000 (13:53 +0100)
Change-Id: I9fa8b488b72e685264304fe213974da7bfcca737
Signed-off-by: Adam Szczerbiak <a.szczerbiak@samsung.com>
src/globalization/cordova_globalization_api.js
src/globalization/cordova_globalization_instance.cc
src/globalization/cordova_globalization_tools.cc
src/globalization/cordova_globalization_tools.h

index 4ddfe3ac4d6077fa0938510b5c3df797377e843e..42b6a84fb3039a05e4359ed7253ebcb1ba5655be 100755 (executable)
@@ -103,7 +103,7 @@ function Globalization_getDatePattern(successCb, errorCb, options) {
   var selector = (options && options.selector) || selectorDateAndTimeStr;
 
   var callback = function(result) {
-    // Checking succes of gathering pattern
+    // Checking success of gathering pattern
     var fullResult = {};
     if (native_.isFailure(result)) {
       var error = new GlobalizationError(
@@ -118,19 +118,13 @@ function Globalization_getDatePattern(successCb, errorCb, options) {
     // looking for missing pieces of fullResult object
     var currentDateTime = tizen.time.getCurrentDateTime();
     if (currentDateTime) {
-      // TODO currently value as "GMT+09:00" will be returned,
-      // to get value "Asia/Seoul" use .getTimezone() instead
-      var timezoneAbbreviation = currentDateTime.getTimezoneAbbreviation();
-
       // TODO method secondsFromUTC returns inverted offset: if time zone is GMT+8, it will return -32,400.
       // TODO currently utcOffset will include DST additional hour if it is present, value will be
       // timezoneOffset = timezoneOffsetWithoutDST + DSTAdditionalOffset
-      // if other behaviour is correct, just need to substract dstOffset from utcOffset
+      // if other behavior is correct, just need to subtract dstOffset from utcOffset
       var utcOffset = currentDateTime.secondsFromUTC() * (-1);
       var dstOffset = currentDateTime.isDST() ? oneHourSeconds : 0;
 
-      //adding missing parts of result
-      fullResult["timezone"] = timezoneAbbreviation;
       fullResult["utc_offset"] = utcOffset;
       fullResult["dst_offset"] = dstOffset;
       successCb(fullResult);
@@ -147,6 +141,7 @@ function Globalization_getDatePattern(successCb, errorCb, options) {
   native_.call('CordovaGlobalization_getDatePattern', callArgs, callback);
 }
 
+
 function Globalization_getDateNames(successCb, errorCb, options) {
   var type = (options && options.type) || typeWide;
   var item = (options && options.item) || itemMonths;
@@ -167,6 +162,7 @@ function Globalization_getDateNames(successCb, errorCb, options) {
   native_.call('CordovaGlobalization_getDateNames', callArgs, callback);
 }
 
+
 function Globalization_isDayLightSavingsTime(timestamp, successCb, errorCb) {
   var tzdate = new tizen.TZDate(new Date(timestamp)); //creates tzdate with local default timezone
   if (tzdate) {
index 94c6a36e99a773ea44cddc8acff7a5c1e9579e4d..cae29c9bb5bbf34a728ddcdd8980a6b55b30f16c 100644 (file)
@@ -185,10 +185,16 @@ void CordovaGlobalizationInstance::GetDatePattern(const picojson::value& args,
       picojson::value result = picojson::value(picojson::object());
       picojson::object& result_obj = result.get<picojson::object>();
 
-      // returning only pattern of date, rest of result should be added in JS using web device API
       result_obj.insert(std::make_pair("pattern", picojson::value(result_str)));
 
-      ReportSuccess(result, response->get<picojson::object>());
+      std::string result_str;
+      ret = CordovaGlobalizationTools::GetTimezoneAbbreviation(&result_str);
+      if (ret.IsSuccess()) {
+        result_obj.insert(std::make_pair("timezone", picojson::value(result_str)));
+        ReportSuccess(result, response->get<picojson::object>());
+      } else {
+        ReportError(ret, &(response->get<picojson::object>()));
+      }
     } else {
       ReportError(ret, &(response->get<picojson::object>()));
     }
index c084ff3a27f1c784ec6b5736302ab19f1e411ff2..d4af43a7351665c0da45e68cac49e6f06d70485d 100644 (file)
@@ -65,6 +65,7 @@ Locale CordovaGlobalizationTools::GetDefaultLocale() {
       return result;
     }
   }
+
   return Locale::createFromName("en_US");
 }
 
@@ -171,6 +172,39 @@ PlatformResult CordovaGlobalizationTools::GetDatePattern(DateFormat::EStyle form
   return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get date pattern");
 }
 
+
+PlatformResult CordovaGlobalizationTools::GetTimezoneAbbreviation(std::string *result_string) {
+  LoggerD("Entered");
+  UErrorCode uec = U_ZERO_ERROR;
+  UnicodeString str;
+  PlatformResult pr(ErrorCode::NO_ERROR);
+  std::unique_ptr<DateFormat> fmt(
+      new SimpleDateFormat(UnicodeString("z"), Locale::getEnglish(), uec));
+  if (U_SUCCESS(uec)) {
+    std::unique_ptr<TimeZone> tz(TimeZone::createDefault());
+    fmt->setTimeZone(*tz);
+    fmt->format(0L, str);
+    if ((str.length() > 3) && (str.compare(0, 3, "GMT") == 0)) {
+      LoggerD("Returned time zone is a GMT offset.");
+      str.remove();
+      std::unique_ptr<DateFormat> gmt(
+          new SimpleDateFormat(UnicodeString("OOOO"), Locale::getEnglish(), uec));
+      gmt->setTimeZone(*tz);
+      gmt->format(0L, str);
+    } else {
+      LoggerD("Returned time zone is not a GMT offset.");
+    }
+
+    *result_string = ToUTF8String(str);
+  } else {
+    LoggerE("Error: could not obtain the time zone.");
+    *result_string = "";
+    pr = PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not obtain the time zone.");
+  }
+
+  return pr;
+}
+
 PlatformResult CordovaGlobalizationTools::GetNames(const std::string& item,
                                                    const std::string& type,
                                                    std::vector<std::string>* result) {
index 9703d558a53fa43547d1fa5dbf8f8ac20548bbff..c60fb07f38c05b6608d0fc6f636360f4bcc07148 100644 (file)
@@ -56,7 +56,7 @@ class CordovaGlobalizationTools{
                                                       const std::string& selector);
   static DateFormat::EStyle GetDateFormat(const std::string& length);
   static std::string GetDateString(UDate date, DateFormat::EStyle format,
-                                              const std::string& selector);
+                                   const std::string& selector);
   static common::PlatformResult GetUDateFromString(const std::string& date,
                                                    DateFormat::EStyle format,
                                                    const std::string& selector,
@@ -64,8 +64,9 @@ class CordovaGlobalizationTools{
   static common::PlatformResult GetDatePattern(DateFormat::EStyle format,
                                                const std::string& selector,
                                                std::string* result);
+  static common::PlatformResult GetTimezoneAbbreviation(std::string *result_tring);
   static common::PlatformResult GetNames(const std::string& item, const std::string& type,
-                                             std::vector<std::string>* result);
+                                         std::vector<std::string>* result);
   static common::PlatformResult GetFirstDayOfWeek(double* result);
   static common::PlatformResult FormatNumber(double number, const std::string& type,
                                              std::string* result);