You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2019/03/26 18:08:50 UTC
[royale-asjs] branch develop updated: formatters: add
getDateFromString to IDateFormatter to create a Date object from a
formatted date string
This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 23c9ef1 formatters: add getDateFromString to IDateFormatter to create a Date object from a formatted date string
23c9ef1 is described below
commit 23c9ef1a8186f4cc3f180bdfb2b2d98afab8c443
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Tue Mar 26 19:08:43 2019 +0100
formatters: add getDateFromString to IDateFormatter to create a Date object from a formatted date string
---
.../org/apache/royale/core/IDateFormatter.as | 2 ++
.../royale/html/accessories/SimpleDateFormatter.as | 41 ++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IDateFormatter.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IDateFormatter.as
index 5dc49cf..2654a8e 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IDateFormatter.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/core/IDateFormatter.as
@@ -31,5 +31,7 @@ package org.apache.royale.core
{
function get dateFormat():String;
function set dateFormat(value:String):void;
+
+ function getDateFromString(str:String):Date
}
}
\ No newline at end of file
diff --git a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
index 24d087a..74a02c4 100644
--- a/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
+++ b/frameworks/projects/Formatters/src/main/royale/org/apache/royale/html/accessories/SimpleDateFormatter.as
@@ -139,5 +139,46 @@ package org.apache.royale.html.accessories
return result;
}
+ /**
+ * Returns a Date created from a date string
+ *
+ * @param str, the date formated string. Some examples of valid formats are MM/DD/YYYY, DD/MM/YYYY
+ * @return the date object generated from the string or null
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.6
+ */
+ public function getDateFromString(str:String):Date
+ {
+ if (str != null) {
+ var month:int;
+ var day:int;
+ var year:int;
+ var tokens:Array = dateFormat.split(_separator);
+ var strtokens:Array = str.split(_separator);
+ var length:int = tokens.length;
+
+ for (var i:int = 0; i < length; i++) {
+ switch (tokens[i]) {
+ case "YYYY":
+ year = int(strtokens[i]);
+ break;
+ case "YY":
+ year = 2000 + int(strtokens[i]);
+ break;
+ case "MM" || "M":
+ month = int(strtokens[i]) - 1;
+ break;
+ case "DD" || "D":
+ day = int(strtokens[i]);
+ break;
+ }
+ }
+
+ return new Date(year, month, day);
+ }
+ return null;
+ }
}
}