You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2013/04/22 12:25:01 UTC

[1/3] git commit: [flex-sdk] - FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months

Updated Branches:
  refs/heads/develop 97a9298cc -> ec15ddde1


FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/2dd706e5
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/2dd706e5
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/2dd706e5

Branch: refs/heads/develop
Commit: 2dd706e57f31c906003eaac4d300f7ed845c3113
Parents: 97a9298
Author: Justin Mclean <jm...@apache.org>
Authored: Mon Apr 22 20:22:02 2013 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Mon Apr 22 20:22:02 2013 +1000

----------------------------------------------------------------------
 .../framework/src/mx/formatters/DateFormatter.as   |   56 ++++++++++-----
 1 files changed, 38 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/2dd706e5/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/framework/src/mx/formatters/DateFormatter.as b/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
index a28c716..e12e990 100644
--- a/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
+++ b/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
@@ -129,6 +129,7 @@ public class DateFormatter extends Formatter
         var hour:int = -1;
         var min:int = -1;
         var sec:int = -1;
+		var milli:int = -1;
         
         var letter:String = "";
         var marker:Object = 0;
@@ -154,7 +155,8 @@ public class DateFormatter extends Formatter
             // If the letter is a key punctuation character,
             // cache it for the next time around.
             if (letter == "/" || letter == ":" ||
-                letter == "+" || letter == "-")
+                letter == "+" || letter == "-" ||
+				letter == ".")
             {
                 marker = letter;
                 continue;
@@ -162,23 +164,27 @@ public class DateFormatter extends Formatter
 
             // Scan for groups of numbers and letters
             // and match them to Date parameters
-            if ("a" <= letter && letter <= "z" ||
-                "A" <= letter && letter <= "Z")
+            if (!("0" <= letter && letter <= "9" ||
+				  letter == "/" || letter == ":" ||
+			      letter == "+" || letter == "-" ||
+				  letter == "." || letter == " "))
             {
                 // Scan for groups of letters
                 var word:String = letter;
                 while (count < len) 
                 {
                     letter = str.charAt(count);
-                    if (!("a" <= letter && letter <= "z" ||
-                          "A" <= letter && letter <= "Z"))
+					if ("0" <= letter && letter <= "9"||
+						letter == "/" || letter == ":" ||
+						letter == "+" || letter == "-" ||
+						letter == "." || letter == " ")
                     {
                         break;
                     }
                     word += letter;
                     count++;
                 }
-
+				
                 // Allow for an exact match
                 // or a match to the first 3 letters as a prefix.
                 var n:int = DateBase.defaultStringKey.length;
@@ -233,7 +239,8 @@ public class DateFormatter extends Formatter
                 var num:int = int(numbers);
 
                 // If num is a number greater than 70, assign num to year.
-                if (num >= 70)
+				// if after seconds and a dot or colon more likly milliseconds
+                if (num >= 70 && !((marker == "." || marker == ":") && sec >= 0))
                 {
                     if (year != -1)
                     {
@@ -251,25 +258,29 @@ public class DateFormatter extends Formatter
                 }
 
                 // If the current letter is a slash or a dash,
-                // assign num to month or day.
+                // assign num to month or day or sec.
                 else if (letter == "/" || letter == "-" || letter == ".")
                 {
                     if (mon < 0)
                         mon = (num - 1);
-                    else if (day < 0)
-                        day = num;
+					else if (day < 0)
+						day = num;
+					else if (sec < 0)
+						sec = num;
                     else
                         break; //error
                 }
 
                 // If the current letter is a colon,
-                // assign num to hour or minute.
+                // assign num to hour or minute or sec.
                 else if (letter == ":")
                 {
                     if (hour < 0)
                         hour = num;
                     else if (min < 0)
                         min = num;
+					else if (sec < 0)
+						sec = num;
                     else
                         break; //error
                 }
@@ -281,12 +292,19 @@ public class DateFormatter extends Formatter
                     min = num;
                 }
 
-                // If minutes are defined and seconds are not,
-                // assign num to seconds.
-                else if (min >= 0 && sec < 0)
-                {
-                    sec = num;
-                }
+				// If minutes are defined and seconds are not,
+				// assign num to seconds.
+				else if (min >= 0 && sec < 0)
+				{
+					sec = num;
+				}
+				
+				// If seconds are defined and millis are not,
+				// assign num to mills.
+				else if (sec >= 0 && milli < 0)
+				{
+					milli = num;
+				}
 
                 // If day is not defined, assign num to day.
                 else if (day < 0)
@@ -315,6 +333,8 @@ public class DateFormatter extends Formatter
             return null; // error - needs to be a date
 
         // Time is set to 0 if null.
+		if (milli < 0)
+			milli = 0;
         if (sec < 0)
             sec = 0;
         if (min < 0)
@@ -324,7 +344,7 @@ public class DateFormatter extends Formatter
 
         // create a date object and check the validity of the input date
         // by comparing the result with input values.
-        var newDate:Date = new Date(year, mon, day, hour, min, sec);
+        var newDate:Date = new Date(year, mon, day, hour, min, sec, milli);
         if (day != newDate.getDate() || mon != newDate.getMonth())
             return null;
 


[3/3] git commit: [flex-sdk] - Fixed field sizes and added extra .millisecond test

Posted by jm...@apache.org.
Fixed field sizes and added extra .millisecond test


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/ec15ddde
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/ec15ddde
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/ec15ddde

Branch: refs/heads/develop
Commit: ec15ddde1f798c4dca45991adfbe46130c832f55
Parents: 68c2a9b
Author: Justin Mclean <jm...@apache.org>
Authored: Mon Apr 22 20:24:28 2013 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Mon Apr 22 20:24:28 2013 +1000

----------------------------------------------------------------------
 .../tests/Formatters/SWFs/DateFormatter_Main.mxml  |   24 ++++++++-------
 1 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/ec15ddde/mustella/tests/Formatters/SWFs/DateFormatter_Main.mxml
----------------------------------------------------------------------
diff --git a/mustella/tests/Formatters/SWFs/DateFormatter_Main.mxml b/mustella/tests/Formatters/SWFs/DateFormatter_Main.mxml
index a782c18..1946c62 100644
--- a/mustella/tests/Formatters/SWFs/DateFormatter_Main.mxml
+++ b/mustella/tests/Formatters/SWFs/DateFormatter_Main.mxml
@@ -17,7 +17,7 @@
   limitations under the License.
 
 -->
-<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="800" height="700" horizontalAlign="center">
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="850" height="700" horizontalAlign="center">
 
 <!--
 	http://livedocs.adobe.com/flex/3/langref/mx/formatters/DateFormatter.html
@@ -175,6 +175,7 @@
 
 					// millisec
 					dateFormatOutputDefaultMaskMillisec.text = dtFormatterMaskMillisec.format(aDate);
+					dateFormatOutputDefaultMaskAltMillisec.text = dtFormatterMaskALtMillisec.format(aDate);
 
 				  	//deafult toDateString
 				  	dateStringOutput.text = aDateString;
@@ -233,6 +234,7 @@
 	<mx:DateFormatter id="dtFormatterMaskMedium" formatString="MMM. D, YYYY"/>
 	<mx:DateFormatter id="dtFormatterMaskTime" formatString="L:NN A"/>
 	<mx:DateFormatter id="dtFormatterMaskMillisec" formatString="EEEE, MMMM DD, YYYY at HH:NN:SS:QQQ A"/>
+	<mx:DateFormatter id="dtFormatterMaskALtMillisec" formatString="EEEE, MMMM DD, YYYY at HH:NN:SS.QQQ A"/>
 
 	<!-- set up some anal date part formats-->
 	<mx:DateFormatter id="dtFormatterDatePartYY" formatString="YY"/>
@@ -279,17 +281,17 @@
 		<mx:Panel layout="horizontal" title="Results" verticalGap="10" height="100%" width="100%" horizontalAlign="center" verticalAlign="middle">
 			<mx:VBox horizontalAlign="center" verticalAlign="top" width="60%" paddingLeft="5">
 				<mx:Label text="Standard Date Masks"/>
-				<mx:TextInput id="dateFormatOutputDefaultStr" width="215"/>
-				<mx:TextInput id="dateFormatOutputDefaultObj"  width="215"/>
-
-				<mx:TextInput id="dateFormatOutputDefaultMaskFull"  width="215"/>
-				<mx:TextInput id="dateFormatOutputDefaultMaskLong"  width="215"/>
-				<mx:TextInput id="dateFormatOutputDefaultMaskMedium"  width="215"/>
-				<mx:TextInput id="dateFormatOutputDefaultMaskTime"  width="215"/>
-				<mx:TextInput id="dateFormatOutputDefaultMaskMillisec"  width="215"/>
+				<mx:TextInput id="dateFormatOutputDefaultStr" width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultObj"  width="300"/>
+
+				<mx:TextInput id="dateFormatOutputDefaultMaskFull"  width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultMaskLong"  width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultMaskMedium"  width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultMaskTime"  width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultMaskMillisec"  width="300"/>
+				<mx:TextInput id="dateFormatOutputDefaultMaskAltMillisec"  width="300"/>
 				
-
-				<mx:TextInput id="dateStringOutput" width="215"/>
+				<mx:TextInput id="dateStringOutput" width="300"/>
 			</mx:VBox>
 
 			<mx:VBox horizontalAlign="center" width="40%" paddingTop="5" paddingBottom="5">


[2/3] git commit: [flex-sdk] - Added test to check .milliseconds

Posted by jm...@apache.org.
Added test to check .milliseconds


Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/68c2a9b8
Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/68c2a9b8
Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/68c2a9b8

Branch: refs/heads/develop
Commit: 68c2a9b863f34a24f7d1b72853f28f6b6985eda8
Parents: 2dd706e
Author: Justin Mclean <jm...@apache.org>
Authored: Mon Apr 22 20:23:31 2013 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Mon Apr 22 20:23:31 2013 +1000

----------------------------------------------------------------------
 .../Properties/DateFormatter_Main_tester.mxml      |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/68c2a9b8/mustella/tests/Formatters/Properties/DateFormatter_Main_tester.mxml
----------------------------------------------------------------------
diff --git a/mustella/tests/Formatters/Properties/DateFormatter_Main_tester.mxml b/mustella/tests/Formatters/Properties/DateFormatter_Main_tester.mxml
index 7bd6297..2aa749c 100644
--- a/mustella/tests/Formatters/Properties/DateFormatter_Main_tester.mxml
+++ b/mustella/tests/Formatters/Properties/DateFormatter_Main_tester.mxml
@@ -373,6 +373,8 @@
 		  <AssertPropertyValue propertyName="text" value="Nov. 28, 2008" target="dateFormatOutputDefaultMaskMedium"/>
 		  <AssertPropertyValue propertyName="text" value="2:34 PM" target="dateFormatOutputDefaultMaskTime"/>
 		  <AssertPropertyValue propertyName="text" value="Fri Nov 28 2008" target="dateStringOutput"/>
+		  <AssertPropertyValue propertyName="text" value="Friday, November. 28, 2008 at 2:34:00:000 PM" target="dateFormatOutputDefaultMaskMillisec"/> 
+		  <AssertPropertyValue propertyName="text" value="Friday, November. 28, 2008 at 2:34:00.000 PM" target="dateFormatOutputDefaultMaskAltMillisec"/> 
   	  </body>
   </TestCase>
  
@@ -387,7 +389,8 @@
 		<AssertPropertyValue propertyName="text" value="Sep. 17, 2009" target="dateFormatOutputDefaultMaskMedium"/>
 		<AssertPropertyValue propertyName="text" value="3:39 PM" target="dateFormatOutputDefaultMaskTime"/>
 		<AssertPropertyValue propertyName="text" value="Thu Sep 17 2009" target="dateStringOutput"/>
-		<AssertPropertyValue propertyName="text" value="Thursday, September 17, 2009 at 15:39:20:789 PM" target="dateFormatOutputDefaultMaskMillisec"/>            
+		<AssertPropertyValue propertyName="text" value="Thursday, September 17, 2009 at 15:39:20:789 PM" target="dateFormatOutputDefaultMaskMillisec"/> 
+		<AssertPropertyValue propertyName="text" value="Thursday, September 17, 2009 at 15:39:20.789 PM" target="dateFormatOutputDefaultMaskAltMillisec"/> 
 	</body>
   </TestCase>  
 


Re: [1/3] git commit: [flex-sdk] - FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months

Posted by Justin Mclean <ju...@classsoftware.com>.
HI,

>> True but how many dates do you need to parse in a second? Plus I was keeping
>> to existing code style.
> Not sure.  Like I said, it is optional
Raise it as a minor JIRA and I'll eventually get to it.

> , and I forgot to say thanks for plowing through all of this broken date stuff.
Rather sad state of affairs reading through all of the unloved JIRA issues. :-)

> One scenario might be: parsing dates from a SOAP response with a lot of
> rows?  What code parses the dates there?
No idea but I'd assume it's just Date.parse() which has it's own issues.

Justin

Re: [1/3] git commit: [flex-sdk] - FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months

Posted by Alex Harui <ah...@adobe.com>.


On 4/22/13 8:26 AM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
> 
>> This many checks in an if statement usually runs faster if you do a simple
>> lookup.
> True but how many dates do you need to parse in a second? Plus I was keeping
> to existing code style.
Not sure.  Like I said, it is optional, and I forgot to say thanks for
plowing through all of this broken date stuff.

One scenario might be: parsing dates from a SOAP response with a lot of
rows?  What code parses the dates there?

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: [1/3] git commit: [flex-sdk] - FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> This many checks in an if statement usually runs faster if you do a simple
> lookup.
True but how many dates do you need to parse in a second? Plus I was keeping to existing code style.

I not measured how long parseDateString takes but I assume it;s only a few ms if that.

Justin

Re: [1/3] git commit: [flex-sdk] - FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of international months

Posted by Alex Harui <ah...@adobe.com>.
Bonus optimization if you have time for this pattern:

> +            if (!("0" <= letter && letter <= "9" ||
> +                  letter == "/" || letter == ":" ||
> +                  letter == "+" || letter == "-" ||
> +                  letter == "." || letter == " "))
This many checks in an if statement usually runs faster if you do a simple
lookup.  Setup the lookup like something like this:
    public static var dateLetters:Object = initDateLetters();
    public static function initDateLetters():Object {
        var letters:Object = {};
        letters['/'] = 1;
        ...
        letters[' '] = 1;
        return letters;
    }
And then the if statement just looks like:
        if (!("0" <= letter && letter <= "9" || dateLetters[letter]) ...

Also, having the static public lookup table allows folks to muck with it.


On 4/22/13 3:25 AM, "jmclean@apache.org" <jm...@apache.org> wrote:

> Updated Branches:
>   refs/heads/develop 97a9298cc -> ec15ddde1
> 
> 
> FLEX-24411 FLEX-20322 added support for .milliseconds and fix parsing of
> international months
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/flex-sdk/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-sdk/commit/2dd706e5
> Tree: http://git-wip-us.apache.org/repos/asf/flex-sdk/tree/2dd706e5
> Diff: http://git-wip-us.apache.org/repos/asf/flex-sdk/diff/2dd706e5
> 
> Branch: refs/heads/develop
> Commit: 2dd706e57f31c906003eaac4d300f7ed845c3113
> Parents: 97a9298
> Author: Justin Mclean <jm...@apache.org>
> Authored: Mon Apr 22 20:22:02 2013 +1000
> Committer: Justin Mclean <jm...@apache.org>
> Committed: Mon Apr 22 20:22:02 2013 +1000
> 
> ----------------------------------------------------------------------
>  .../framework/src/mx/formatters/DateFormatter.as   |   56 ++++++++++-----
>  1 files changed, 38 insertions(+), 18 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/flex-sdk/blob/2dd706e5/frameworks/proje
> cts/framework/src/mx/formatters/DateFormatter.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
> b/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
> index a28c716..e12e990 100644
> --- a/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
> +++ b/frameworks/projects/framework/src/mx/formatters/DateFormatter.as
> @@ -129,6 +129,7 @@ public class DateFormatter extends Formatter
>          var hour:int = -1;
>          var min:int = -1;
>          var sec:int = -1;
> +  var milli:int = -1;
>          
>          var letter:String = "";
>          var marker:Object = 0;
> @@ -154,7 +155,8 @@ public class DateFormatter extends Formatter
>              // If the letter is a key punctuation character,
>              // cache it for the next time around.
>              if (letter == "/" || letter == ":" ||
> -                letter == "+" || letter == "-")
> +                letter == "+" || letter == "-" ||
> +    letter == ".")
>              {
>                  marker = letter;
>                  continue;
> @@ -162,23 +164,27 @@ public class DateFormatter extends Formatter
>  
>              // Scan for groups of numbers and letters
>              // and match them to Date parameters
> -            if ("a" <= letter && letter <= "z" ||
> -                "A" <= letter && letter <= "Z")
> +            if (!("0" <= letter && letter <= "9" ||
> +      letter == "/" || letter == ":" ||
> +         letter == "+" || letter == "-" ||
> +      letter == "." || letter == " "))
>              {
>                  // Scan for groups of letters
>                  var word:String = letter;
>                  while (count < len)
>                  {
>                      letter = str.charAt(count);
> -                    if (!("a" <= letter && letter <= "z" ||
> -                          "A" <= letter && letter <= "Z"))
> +     if ("0" <= letter && letter <= "9"||
> +      letter == "/" || letter == ":" ||
> +      letter == "+" || letter == "-" ||
> +      letter == "." || letter == " ")
>                      {
>                          break;
>                      }
>                      word += letter;
>                      count++;
>                  }
> -
> +    
>                  // Allow for an exact match
>                  // or a match to the first 3 letters as a prefix.
>                  var n:int = DateBase.defaultStringKey.length;
> @@ -233,7 +239,8 @@ public class DateFormatter extends Formatter
>                  var num:int = int(numbers);
>  
>                  // If num is a number greater than 70, assign num to year.
> -                if (num >= 70)
> +    // if after seconds and a dot or colon more likly milliseconds
> +                if (num >= 70 && !((marker == "." || marker == ":") && sec >=
> 0))
>                  {
>                      if (year != -1)
>                      {
> @@ -251,25 +258,29 @@ public class DateFormatter extends Formatter
>                  }
>  
>                  // If the current letter is a slash or a dash,
> -                // assign num to month or day.
> +                // assign num to month or day or sec.
>                  else if (letter == "/" || letter == "-" || letter == ".")
>                  {
>                      if (mon < 0)
>                          mon = (num - 1);
> -                    else if (day < 0)
> -                        day = num;
> +     else if (day < 0)
> +      day = num;
> +     else if (sec < 0)
> +      sec = num;
>                      else
>                          break; //error
>                  }
>  
>                  // If the current letter is a colon,
> -                // assign num to hour or minute.
> +                // assign num to hour or minute or sec.
>                  else if (letter == ":")
>                  {
>                      if (hour < 0)
>                          hour = num;
>                      else if (min < 0)
>                          min = num;
> +     else if (sec < 0)
> +      sec = num;
>                      else
>                          break; //error
>                  }
> @@ -281,12 +292,19 @@ public class DateFormatter extends Formatter
>                      min = num;
>                  }
>  
> -                // If minutes are defined and seconds are not,
> -                // assign num to seconds.
> -                else if (min >= 0 && sec < 0)
> -                {
> -                    sec = num;
> -                }
> +    // If minutes are defined and seconds are not,
> +    // assign num to seconds.
> +    else if (min >= 0 && sec < 0)
> +    {
> +     sec = num;
> +    }
> +    
> +    // If seconds are defined and millis are not,
> +    // assign num to mills.
> +    else if (sec >= 0 && milli < 0)
> +    {
> +     milli = num;
> +    }
>  
>                  // If day is not defined, assign num to day.
>                  else if (day < 0)
> @@ -315,6 +333,8 @@ public class DateFormatter extends Formatter
>              return null; // error - needs to be a date
>  
>          // Time is set to 0 if null.
> +  if (milli < 0)
> +   milli = 0;
>          if (sec < 0)
>              sec = 0;
>          if (min < 0)
> @@ -324,7 +344,7 @@ public class DateFormatter extends Formatter
>  
>          // create a date object and check the validity of the input date
>          // by comparing the result with input values.
> -        var newDate:Date = new Date(year, mon, day, hour, min, sec);
> +        var newDate:Date = new Date(year, mon, day, hour, min, sec, milli);
>          if (day != newDate.getDate() || mon != newDate.getMonth())
>              return null;
>  
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui