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(
// 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);
native_.call('CordovaGlobalization_getDatePattern', callArgs, callback);
}
+
function Globalization_getDateNames(successCb, errorCb, options) {
var type = (options && options.type) || typeWide;
var item = (options && options.item) || itemMonths;
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) {
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>()));
}
return result;
}
}
+
return Locale::createFromName("en_US");
}
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) {
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,
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);