You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/07/30 21:06:37 UTC
[20/38] git commit: BB10: Implement isDayLightSavingsTime.
BB10: Implement isDayLightSavingsTime.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/a1719f95
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/a1719f95
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/a1719f95
Branch: refs/heads/lyon-g11n
Commit: a1719f959f34a3d81dc75c0b385b42520e9b5027
Parents: 1a26c0e
Author: Lianghui Chen <li...@blackberry.com>
Authored: Thu Jul 24 15:33:00 2014 -0400
Committer: Lianghui Chen <li...@blackberry.com>
Committed: Mon Jul 28 15:10:46 2014 -0400
----------------------------------------------------------------------
.../native/src/globalization_ndk.cpp | 47 +++++++++++++++++++-
1 file changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/a1719f95/src/blackberry10/native/src/globalization_ndk.cpp
----------------------------------------------------------------------
diff --git a/src/blackberry10/native/src/globalization_ndk.cpp b/src/blackberry10/native/src/globalization_ndk.cpp
index e265ebf..fea9066 100644
--- a/src/blackberry10/native/src/globalization_ndk.cpp
+++ b/src/blackberry10/native/src/globalization_ndk.cpp
@@ -59,6 +59,15 @@ std::string resultInJson(const std::string& value)
return writer.write(root);
}
+std::string resultInJson(bool value)
+{
+ Json::Value root;
+ root["result"] = value;
+
+ Json::FastWriter writer;
+ return writer.write(root);
+}
+
std::string resultInJson(const UDate& date)
{
UErrorCode status = U_ZERO_ERROR;
@@ -546,7 +555,43 @@ std::string GlobalizationNDK::getDateNames(const std::string& args)
std::string GlobalizationNDK::isDayLightSavingsTime(const std::string& args)
{
- return errorInJson(UNKNOWN_ERROR, "Not supported!");
+ if (args.empty()) {
+ slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::isDayLightSavingsTime: no date provided.");
+ return errorInJson(UNKNOWN_ERROR, "No date is provided!");
+ }
+
+ Json::Reader reader;
+ Json::Value root;
+ bool parse = reader.parse(args, root);
+
+ if (!parse) {
+ slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::isDayLightSavingsTime: invalid json data: %s",
+ args.c_str());
+ return errorInJson(PARSING_ERROR, "Parameters not valid json format!");
+ }
+
+ Json::Value dv = root["date"];
+
+ if (!dv.isNumeric()) {
+ slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::isDayLightSavingsTime: invalid date format: %d",
+ dv.type());
+ return errorInJson(PARSING_ERROR, "Invalid date format!");
+ }
+
+ double date = dv.asDouble();
+
+ UErrorCode status = U_ZERO_ERROR;
+ SimpleDateFormat* sdf = new SimpleDateFormat(status);
+ if (!sdf) {
+ slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationNDK::isDayLightSavingsTime: unable to create SimpleDateFormat instance: %d.",
+ status);
+ return errorInJson(UNKNOWN_ERROR, "Unable to create SimpleDateFormat instance!");
+ }
+
+ const TimeZone& tz = sdf->getTimeZone();
+ bool result = tz.inDaylightTime(date, status);
+
+ return resultInJson(result);
}
std::string GlobalizationNDK::getFirstDayOfWeek()