[Verification] 100% passrate.
Change-Id: Ib50b35709938e18134557315ded8603a50632fb7
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
/*
* Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
var utils_ = xwalk.utils;
var native_ = new utils_.NativeManager(extension);
-var _navigator = navigator || {};
-var _global = window || global || {};
-
-///// GlobalizationError //////
-var GlobalizationError = function(code, message) {
- this.code = code;
- this.name = 'GlobalizationError';
- this.message = message || 'Default Message';
- this.stack = (new Error()).stack;
-};
-
-GlobalizationError.prototype = Object.create(Error.prototype);
-GlobalizationError.prototype.constructor = GlobalizationError;
-
-GlobalizationError.UNKNOWN_ERROR = 0;
-GlobalizationError.FORMATTING_ERROR = 1;
-GlobalizationError.PARSING_ERROR = 2;
-GlobalizationError.PATTERN_ERROR = 3;
-
-_global.GlobalizationError = GlobalizationError;
-
-
///// Globalization //////
var selectorDateStr = 'date';
var selectorTimeStr = 'time';
var selectorDateAndTimeStr = selectorDateStr + ' and ' + selectorTimeStr;
-//TODO how to support all those lenghts??
var formatShortStr = 'short';
var formatMediumStr = 'medium';
var formatLongStr = 'long';
var oneHourSeconds = 60*60;
-var Globalization = {};
-
-Globalization.getPreferredLanguage = function(successCb, errorCb) {
- // TODO add validation of parameters
+function Globalization_getPreferredLanguage(successCb, errorCb) {
// TODO Indicates the current language setting in the (LANGUAGE)_(REGION) syntax.
// The language setting is in the ISO 630-2 format and the region setting is in the ISO 3166-1 format.
tizen.systeminfo.getPropertyValue ('LOCALE',
);
}
-Globalization.getLocaleName = function(successCb, errorCb) {
- Globalization.getPreferredLanguage(successCb, errorCb);
-}
-
-//TODO JS implementation of dateToString would support only full length (one format is supprted),
-// but selector for getting only needed values is fully supported
-Globalization.dateToString = function(date, successCb, errorCb, options) {
- // TODO add validation of parameters
- var result = null;
+function Globalization_dateToString(timestamp, successCb, errorCb, options) {
var formatLength = formatFullStr;
var selector = selectorDateAndTimeStr;
if (options) {
selector = options.selector || selectorDateAndTimeStr;
}
- var timestamp = date.getTime();
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
native_.call('CordovaGlobalization_dateToString', callArgs, callback);
}
-//TODO implementation would try to convert string to Date using javascript Date object
-// constructor, options are basically ignored
-Globalization.stringToDate = function(dateString, successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_stringToDate(dateString, successCb, errorCb, options) {
var result = null;
var formatLength = formatFullStr;
var selector = selectorDateAndTimeStr;
native_.call('CordovaGlobalization_stringToDate', callArgs, callback);
}
-Globalization.getDatePattern = function(successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_getDatePattern(successCb, errorCb, options) {
var formatLength = formatFullStr;
var selector = selectorDateAndTimeStr;
var fullResult = {};
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.PATTERN_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.PATTERN_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
return;
} else {
native_.call('CordovaGlobalization_getDatePattern', callArgs, callback);
}
-Globalization.getDateNames = function(successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_getDateNames(successCb, errorCb, options) {
var type = typeWide;
var item = itemDays;
if (options) {
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
successCb(native_.getResultObject(result));
native_.call('CordovaGlobalization_getDateNames', callArgs, callback);
}
-Globalization.isDayLightSavingsTime = function(date, successCb, errorCb) {
- // TODO add validation of parameters
- var tzdate = new tizen.TZDate(date); //creates tzdate with local default timezone
+function Globalization_isDayLightSavingsTime(timestamp, successCb, errorCb) {
+ var tzdate = new tizen.TZDate(new Date(timestamp)); //creates tzdate with local default timezone
if (tzdate) {
var result = tzdate.isDST();
setTimeout( function() {
}, 0);
} else {
setTimeout( function() {
- errorCb(new GlobalizationError(GlobalizationError.UNKNOWN_ERROR , "cannot get information"))
+ errorCb(new GlobalizationError(GlobalizationError.UNKNOWN_ERROR , "cannot get information"));
}, 0);
}
}
-Globalization.getFirstDayOfWeek = function(successCb, errorCb) {
- // TODO add validation of parameters
+function Globalization_getFirstDayOfWeek(successCb, errorCb) {
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
successCb(native_.getResultObject(result));
native_.call('CordovaGlobalization_getFirstDayOfWeek', {}, callback);
}
-Globalization.numberToString = function(number, successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_numberToString(number, successCb, errorCb, options) {
var type = numberTypeDecimal;
if (options) {
type = options.type || numberTypeDecimal;
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.FORMATTING_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.FORMATTING_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
successCb(native_.getResultObject(result));
native_.call('CordovaGlobalization_numberToString', callArgs, callback);
}
-Globalization.stringToNumber = function(numberStr, successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_stringToNumber(numberStr, successCb, errorCb, options) {
var type = numberTypeDecimal;
if (options) {
type = options.type || numberTypeDecimal;
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.PARSING_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.PARSING_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
var result = native_.getResultObject(result);
native_.call('CordovaGlobalization_stringToNumber', callArgs, callback);
}
-Globalization.getNumberPattern = function(successCb, errorCb, options) {
- // TODO add validation of parameters
+function Globalization_getNumberPattern(successCb, errorCb, options) {
var type = numberTypeDecimal;
if (options) {
type = options.type || numberTypeDecimal;
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
successCb(native_.getResultObject(result));
native_.call('CordovaGlobalization_getNumberPattern', callArgs, callback);
}
-Globalization.getCurrencyPattern = function(currencyCode, successCb, errorCb) {
- // TODO add validation of parameters
+function Globalization_getCurrencyPattern(currencyCode, successCb, errorCb) {
var callback = function(result) {
if (native_.isFailure(result)) {
var error = new GlobalizationError(
- GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message)
+ GlobalizationError.UNKNOWN_ERROR , native_.getErrorObject(result).message);
native_.callIfPossible(errorCb, error);
} else {
successCb(native_.getResultObject(result));
native_.call('CordovaGlobalization_getCurrencyPattern', callArgs, callback);
}
-_navigator.globalization = Globalization;
-console.log('Loaded cordova.globalization API');
+//TODO: remove when added to public cordova repository -> begin
+var plugin_name = 'cordova-plugin-device.tizen.Globalization';
+cordova.define(plugin_name, function(require, exports, module) {
+//TODO: remove -> end
+ exports = {
+ getPreferredLanguage: function (successCb, errorCb, args) {
+ Globalization_getPreferredLanguage(successCb, errorCb);
+ },
+ getLocaleName: function (successCb, errorCb, args) {
+ Globalization_getPreferredLanguage(successCb, errorCb);
+ },
+ dateToString: function (successCb, errorCb, args) {
+ Globalization_dateToString(args[0]['date'], successCb, errorCb, args[0]['options']);
+ },
+ stringToDate: function (successCb, errorCb, args) {
+ Globalization_stringToDate(args[0]['dateString'], successCb, errorCb, args[0]['options']);
+ },
+ getDatePattern: function (successCb, errorCb, args) {
+ Globalization_getDatePattern(successCb, errorCb, args[0]['options']);
+ },
+ getDateNames: function (successCb, errorCb, args) {
+ Globalization_getDateNames(successCb, errorCb, args[0]['options']);
+ },
+ isDayLightSavingsTime: function (successCb, errorCb, args) {
+ Globalization_isDayLightSavingsTime(args[0]['date'], successCb, errorCb);
+ },
+ getFirstDayOfWeek: function (successCb, errorCb, args) {
+ Globalization_getFirstDayOfWeek(successCb, errorCb);
+ },
+ numberToString: function (successCb, errorCb, args) {
+ Globalization_numberToString(args[0]['number'], successCb, errorCb, args[0]['options']);
+ },
+ stringToNumber: function (successCb, errorCb, args) {
+ Globalization_stringToNumber(args[0]['numberString'], successCb, errorCb, args[0]['options']);
+ },
+ getNumberPattern: function (successCb, errorCb, args) {
+ Globalization_getNumberPattern(successCb, errorCb, args[0]['options']);
+ },
+ getCurrencyPattern: function (successCb, errorCb, args) {
+ Globalization_getCurrencyPattern(args[0]['currencyCode'], successCb, errorCb);
+ }
+ };
+ require("cordova/exec/proxy").add("Globalization", exports);
+ console.log('Loaded cordova.globalization API');
+//TODO: remove when added to public cordova repository -> begin
+});
+exports = function(require) {
+//this plugin is not loaded via cordova_plugins.js, we need to manually add
+//it to module mapper
+ var mm = require('cordova/modulemapper');
+ mm.runs(plugin_name);
+};
+//TODO: remove -> end
const std::string& timestamp_str = args.get("timestamp").get<std::string>();
UDate date = std::stod(timestamp_str);
- auto get = [this, format_length, selector, date](const std::shared_ptr<picojson::value>& response) -> void {
+ auto get = [this, format_length, selector, date, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
string result_str = CordovaGlobalizationTools::GetDateString(
date, CordovaGlobalizationTools::GetDateFormat(format_length), selector);
const std::string kNumberTypeCurrency = "currency";
Locale CordovaGlobalizationTools::GetDefaultLocale() {
- //TODO add gathering locale according to settings
+ LoggerD("Entered");
+ char* tempstr = vconf_get_str(VCONFKEY_REGIONFORMAT);
+
+ if (nullptr != tempstr){
+ LoggerD("Region: %s", tempstr);
+
+ char* p = strchr(tempstr, '.');
+ int len = strlen(tempstr) - (p != nullptr ? strlen(p) : 0);
+
+ if (len > 0) {
+ char* str_region = strndup(tempstr, len); //.UTF8 => 5
+ free(tempstr);
+ Locale result = Locale::createFromName(str_region);
+ free(str_region);
+ return result;
+ }
+ }
return Locale::createFromName("en_US");
- //return Locale::getUK();
}
std::string CordovaGlobalizationTools::ToUTF8String(const UnicodeString& uni_str) {
*result = tmp_result;
return PlatformResult(ErrorCode::NO_ERROR);
} else {
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get days names");
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not get names");
}
}
PlatformResult CordovaGlobalizationTools::GetFirstDayOfWeek(double* result) {
LoggerD("Entered");
- UnicodeString str;
UErrorCode ec = U_ZERO_ERROR;
std::unique_ptr<DateFormat> dfmt(DateFormat::createDateInstance(DateFormat::kFull,
GetDefaultLocale()));
}
if (U_ZERO_ERROR >= ec) {
nfmt->format(number, str);
- *result = ToUTF8String(str);;
+ *result = ToUTF8String(str);
return PlatformResult(ErrorCode::NO_ERROR);
} else {
return PlatformResult(ErrorCode::UNKNOWN_ERR, "Could not format number");
"Connection"
]
},
+ {
+ "file": "plugins/cordova-plugin-globalization/www/GlobalizationError.js",
+ "id": "cordova-plugin-globalization.GlobalizationError",
+ "clobbers": [
+ "window.GlobalizationError"
+ ]
+ },
+ {
+ "file": "plugins/cordova-plugin-globalization/www/globalization.js",
+ "id": "cordova-plugin-globalization.globalization",
+ "clobbers": [
+ "navigator.globalization"
+ ]
+ }
];
module.exports.metadata =
// TOP OF METADATA
"cordova-plugin-file": "3.0.0",
"cordova-plugin-file-transfer": "1.3.0",
"cordova-plugin-network-information": "1.0.1",
+ "cordova-plugin-globalization": "1.0.1",
}
// BOTTOM OF METADATA
});
--- /dev/null
+cordova.define("cordova-plugin-globalization.GlobalizationError", function(require, exports, module) { /*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+
+/**
+ * Globalization error object
+ *
+ * @constructor
+ * @param code
+ * @param message
+ */
+var GlobalizationError = function(code, message) {
+ this.code = code || null;
+ this.message = message || '';
+};
+
+// Globalization error codes
+GlobalizationError.UNKNOWN_ERROR = 0;
+GlobalizationError.FORMATTING_ERROR = 1;
+GlobalizationError.PARSING_ERROR = 2;
+GlobalizationError.PATTERN_ERROR = 3;
+
+module.exports = GlobalizationError;
+
+});
--- /dev/null
+cordova.define("cordova-plugin-globalization.globalization", function(require, exports, module) { /*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var argscheck = require('cordova/argscheck'),
+ exec = require('cordova/exec'),
+ GlobalizationError = require('./GlobalizationError');
+
+var globalization = {
+
+/**
+* Returns the string identifier for the client's current language.
+* It returns the language identifier string to the successCB callback with a
+* properties object as a parameter. If there is an error getting the language,
+* then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {String}: The language identifier
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getPreferredLanguage(function (language) {alert('language:' + language.value + '\n');},
+* function () {});
+*/
+getPreferredLanguage:function(successCB, failureCB) {
+ argscheck.checkArgs('fF', 'Globalization.getPreferredLanguage', arguments);
+ exec(successCB, failureCB, "Globalization","getPreferredLanguage", []);
+},
+
+/**
+* Returns the string identifier for the client's current locale setting.
+* It returns the locale identifier string to the successCB callback with a
+* properties object as a parameter. If there is an error getting the locale,
+* then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {String}: The locale identifier
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getLocaleName(function (locale) {alert('locale:' + locale.value + '\n');},
+* function () {});
+*/
+getLocaleName:function(successCB, failureCB) {
+ argscheck.checkArgs('fF', 'Globalization.getLocaleName', arguments);
+ exec(successCB, failureCB, "Globalization","getLocaleName", []);
+},
+
+
+/**
+* Returns a date formatted as a string according to the client's user preferences and
+* calendar using the time zone of the client. It returns the formatted date string to the
+* successCB callback with a properties object as a parameter. If there is an error
+* formatting the date, then the errorCB callback is invoked.
+*
+* The defaults are: formatLenght="short" and selector="date and time"
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.value {String}: The localized date string
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.dateToString(new Date(),
+* function (date) {alert('date:' + date.value + '\n');},
+* function (errorCode) {alert(errorCode);},
+* {formatLength:'short'});
+*/
+dateToString:function(date, successCB, failureCB, options) {
+ argscheck.checkArgs('dfFO', 'Globalization.dateToString', arguments);
+ var dateValue = date.valueOf();
+ exec(successCB, failureCB, "Globalization", "dateToString", [{"date": dateValue, "options": options}]);
+},
+
+
+/**
+* Parses a date formatted as a string according to the client's user
+* preferences and calendar using the time zone of the client and returns
+* the corresponding date object. It returns the date to the successCB
+* callback with a properties object as a parameter. If there is an error
+* parsing the date string, then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {String} dateString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.year {Number}: The four digit year
+* Object.month {Number}: The month from (0 - 11)
+* Object.day {Number}: The day from (1 - 31)
+* Object.hour {Number}: The hour from (0 - 23)
+* Object.minute {Number}: The minute from (0 - 59)
+* Object.second {Number}: The second from (0 - 59)
+* Object.millisecond {Number}: The milliseconds (from 0 - 999),
+* not available on all platforms
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+* globalization.stringToDate('4/11/2011',
+* function (date) { alert('Month:' + date.month + '\n' +
+* 'Day:' + date.day + '\n' +
+* 'Year:' + date.year + '\n');},
+* function (errorCode) {alert(errorCode);},
+* {selector:'date'});
+*/
+stringToDate:function(dateString, successCB, failureCB, options) {
+ argscheck.checkArgs('sfFO', 'Globalization.stringToDate', arguments);
+ exec(successCB, failureCB, "Globalization", "stringToDate", [{"dateString": dateString, "options": options}]);
+},
+
+
+/**
+* Returns a pattern string for formatting and parsing dates according to the client's
+* user preferences. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern,
+* then the errorCB callback is invoked.
+*
+* The defaults are: formatLength="short" and selector="date and time"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* formatLength {String}: 'short', 'medium', 'long', or 'full'
+* selector {String}: 'date', 'time', or 'date and time'
+*
+* @return Object.pattern {String}: The date and time pattern for formatting and parsing dates.
+* The patterns follow Unicode Technical Standard #35
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.timezone {String}: The abbreviated name of the time zone on the client
+* Object.utc_offset {Number}: The current difference in seconds between the client's
+* time zone and coordinated universal time.
+* Object.dst_offset {Number}: The current daylight saving time offset in seconds
+* between the client's non-daylight saving's time zone
+* and the client's daylight saving's time zone.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+* globalization.getDatePattern(
+* function (date) {alert('pattern:' + date.pattern + '\n');},
+* function () {},
+* {formatLength:'short'});
+*/
+getDatePattern:function(successCB, failureCB, options) {
+ argscheck.checkArgs('fFO', 'Globalization.getDatePattern', arguments);
+ exec(successCB, failureCB, "Globalization", "getDatePattern", [{"options": options}]);
+},
+
+
+/**
+* Returns an array of either the names of the months or days of the week
+* according to the client's user preferences and calendar. It returns the array of names to the
+* successCB callback with a properties object as a parameter. If there is an error obtaining the
+* names, then the errorCB callback is invoked.
+*
+* The defaults are: type="wide" and item="months"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'narrow' or 'wide'
+* item {String}: 'months', or 'days'
+*
+* @return Object.value {Array{String}}: The array of names starting from either
+* the first month in the year or the
+* first day of the week.
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getDateNames(function (names) {
+* for(var i = 0; i < names.value.length; i++) {
+* alert('Month:' + names.value[i] + '\n');}},
+* function () {});
+*/
+getDateNames:function(successCB, failureCB, options) {
+ argscheck.checkArgs('fFO', 'Globalization.getDateNames', arguments);
+ exec(successCB, failureCB, "Globalization", "getDateNames", [{"options": options}]);
+},
+
+/**
+* Returns whether daylight savings time is in effect for a given date using the client's
+* time zone and calendar. It returns whether or not daylight savings time is in effect
+* to the successCB callback with a properties object as a parameter. If there is an error
+* reading the date, then the errorCB callback is invoked.
+*
+* @param {Date} date
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.dst {Boolean}: The value "true" indicates that daylight savings time is
+* in effect for the given date and "false" indicate that it is not.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.isDayLightSavingsTime(new Date(),
+* function (date) {alert('dst:' + date.dst + '\n');}
+* function () {});
+*/
+isDayLightSavingsTime:function(date, successCB, failureCB) {
+ argscheck.checkArgs('dfF', 'Globalization.isDayLightSavingsTime', arguments);
+ var dateValue = date.valueOf();
+ exec(successCB, failureCB, "Globalization", "isDayLightSavingsTime", [{"date": dateValue}]);
+},
+
+/**
+* Returns the first day of the week according to the client's user preferences and calendar.
+* The days of the week are numbered starting from 1 where 1 is considered to be Sunday.
+* It returns the day to the successCB callback with a properties object as a parameter.
+* If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.value {Number}: The number of the first day of the week.
+*
+* @error GlobalizationError.UNKNOWN_ERROR
+*
+* Example
+* globalization.getFirstDayOfWeek(function (day)
+* { alert('Day:' + day.value + '\n');},
+* function () {});
+*/
+getFirstDayOfWeek:function(successCB, failureCB) {
+ argscheck.checkArgs('fF', 'Globalization.getFirstDayOfWeek', arguments);
+ exec(successCB, failureCB, "Globalization", "getFirstDayOfWeek", []);
+},
+
+
+/**
+* Returns a number formatted as a string according to the client's user preferences.
+* It returns the formatted number string to the successCB callback with a properties object as a
+* parameter. If there is an error formatting the number, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Number} number
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {String}: The formatted number string.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.numberToString(3.25,
+* function (number) {alert('number:' + number.value + '\n');},
+* function () {},
+* {type:'decimal'});
+*/
+numberToString:function(number, successCB, failureCB, options) {
+ argscheck.checkArgs('nfFO', 'Globalization.numberToString', arguments);
+ exec(successCB, failureCB, "Globalization", "numberToString", [{"number": number, "options": options}]);
+},
+
+/**
+* Parses a number formatted as a string according to the client's user preferences and
+* returns the corresponding number. It returns the number to the successCB callback with a
+* properties object as a parameter. If there is an error parsing the number string, then
+* the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {String} numberString
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.value {Number}: The parsed number.
+*
+* @error GlobalizationError.PARSING_ERROR
+*
+* Example
+* globalization.stringToNumber('1234.56',
+* function (number) {alert('Number:' + number.value + '\n');},
+* function () { alert('Error parsing number');});
+*/
+stringToNumber:function(numberString, successCB, failureCB, options) {
+ argscheck.checkArgs('sfFO', 'Globalization.stringToNumber', arguments);
+ exec(successCB, failureCB, "Globalization", "stringToNumber", [{"numberString": numberString, "options": options}]);
+},
+
+/**
+* Returns a pattern string for formatting and parsing numbers according to the client's user
+* preferences. It returns the pattern to the successCB callback with a properties object as a
+* parameter. If there is an error obtaining the pattern, then the errorCB callback is invoked.
+*
+* The defaults are: type="decimal"
+*
+* @param {Function} successCB
+* @param {Function} errorCB
+* @param {Object} options {optional}
+* type {String}: 'decimal', "percent", or 'currency'
+*
+* @return Object.pattern {String}: The number pattern for formatting and parsing numbers.
+* The patterns follow Unicode Technical Standard #35.
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.symbol {String}: The symbol to be used when formatting and parsing
+* e.g., percent or currency symbol.
+* Object.fraction {Number}: The number of fractional digits to use when parsing and
+* formatting numbers.
+* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+* Object.positive {String}: The symbol to use for positive numbers when parsing and formatting.
+* Object.negative: {String}: The symbol to use for negative numbers when parsing and formatting.
+* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.PATTERN_ERROR
+*
+* Example
+* globalization.getNumberPattern(
+* function (pattern) {alert('Pattern:' + pattern.pattern + '\n');},
+* function () {});
+*/
+getNumberPattern:function(successCB, failureCB, options) {
+ argscheck.checkArgs('fFO', 'Globalization.getNumberPattern', arguments);
+ exec(successCB, failureCB, "Globalization", "getNumberPattern", [{"options": options}]);
+},
+
+/**
+* Returns a pattern string for formatting and parsing currency values according to the client's
+* user preferences and ISO 4217 currency code. It returns the pattern to the successCB callback with a
+* properties object as a parameter. If there is an error obtaining the pattern, then the errorCB
+* callback is invoked.
+*
+* @param {String} currencyCode
+* @param {Function} successCB
+* @param {Function} errorCB
+*
+* @return Object.pattern {String}: The currency pattern for formatting and parsing currency values.
+* The patterns follow Unicode Technical Standard #35
+* http://unicode.org/reports/tr35/tr35-4.html
+* Object.code {String}: The ISO 4217 currency code for the pattern.
+* Object.fraction {Number}: The number of fractional digits to use when parsing and
+* formatting currency.
+* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
+* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
+* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
+*
+* @error GlobalizationError.FORMATTING_ERROR
+*
+* Example
+* globalization.getCurrencyPattern('EUR',
+* function (currency) {alert('Pattern:' + currency.pattern + '\n');}
+* function () {});
+*/
+getCurrencyPattern:function(currencyCode, successCB, failureCB) {
+ argscheck.checkArgs('sfF', 'Globalization.getCurrencyPattern', arguments);
+ exec(successCB, failureCB, "Globalization", "getCurrencyPattern", [{"currencyCode": currencyCode}]);
+}
+
+};
+
+module.exports = globalization;
+
+});