You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Justin Mclean <ju...@classsoftware.com> on 2013/04/19 05:42:40 UTC

DateField Issues and fixes

Hi,

I've been looking at DataField and it has a few problems mostly how it dealing with format string parsing in stringToDate and dateToString static methods. 

There are several unresolved JIRA issues around this component.

Some of the issues include.

1. Poor support of "M" and "D" vs "MM" and "DD". Currently:
1/10/2013 formatted with D/M/YY = null
1/10/2013 formatted with D/MM/YY = null
1/10/2013 formatted with M/D/YY = null
7/17/69 formatted with M/D/YY = null
1/30/13 formatted with M/D/YY = null

And also this - which is just plain wrong! It should either reject the format as being invalid or be able to deal with it.

Tue Oct 1 00:00:00 GMT+1000 2013 formatted with D/M/YY = 1/1013
Thu Jul 17 00:00:00 GMT+1000 1969 formatted with M/D/YY = 7/1769
Thu Jul 17 00:00:00 GMT+1000 1969 formatted with D/M/YY = 177/69
Tue Oct 1 00:00:00 GMT+1000 2013 formatted with M/D = 1001

2. Invalid formatting of invalid dates
Invalid Date formatted with DD/MM/YYYY = NaN/NaN/NaN 

3. Magic cut off in 1970.
7/17/71 formatted with MM/DD/YYYY = Sat Jul 17 00:00:00 GMT+1000 1971
7/17/69 formatted with MM/DD/YYYY = Wed Jul 17 00:00:00 GMT+1100 2069

I've  rewritten the methods in a cleaner way that support a wider range of formats and fixes all the issue above.

The code is in the style of the existing SDK code (which is a little ugly IMO). Any feedback,potential bug etc etc would be appreciated.

There a bit more work to do with stringToDate and support for formats without separators - which might be tricky.

The mustella DateField tests all pass however I believe it only tests the US centric MM/DD/YYYY format.

     [java] =====================================================
     [java]     Passes: 327
     [java]     Fails: 0
     [java] =====================================================

Thanks
Justin




Re: DateField Issues and fixes

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

Thanks for that I take a look tomorrow.

I have to ask did you write all the code yourself and are able to donate it to Apache Flex? From what I can see it's under a Apache style licence already.
https://github.com/JabbyPanda/DateField4/blob/master/LICENSE

Thanks,
Justin

Re: DateField Issues and fixes

Posted by Andriy Panas <ja...@gmail.com>.
Hi Justin,

FYI, few years ago, I did a closer examination of existing limitations of
current DateFormatter from Flex3 and suggested a few fixes for the
following issues (old JIRA numeration):

Fixed SDK-23069  <https://bugs.adobe.com/jira/browse/SDK-23069>[Localization]:
DateFormatter.parseDateString does not support non-latin characters in
month and days names;

Fixed SDK-23075 <https://bugs.adobe.com/jira/browse/SDK-23075> “[Localization]:
DateField should support “MMM” and “MMMM” for formatString”;

Fixed SDK-26715 <https://bugs.adobe.com/jira/browse/SDK-26715> “DateFormatter
“parseDateString” method cannot parse dateString value formatted with non
default en_US format”;

Demo:
http://jabbypanda.com/blog/2010/12/datefield4-component-for-flex-4-sdk/

If you are interested in code, it is available at the Github

https://github.com/JabbyPanda/DateField4



On 20 April 2013 08:57, Alex Harui <ah...@adobe.com> wrote:

>
>
>
> On 4/19/13 5:28 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:
>
> >
> > Alex if you could review the tests as I'm not 100% familiar with
> Mustella I'd
> > appreciate it.
> >
> Looks like the right pattern for testing methods.  Good job!
>
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>
>

Re: DateField Issues and fixes

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


On 4/19/13 5:28 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> 
> Alex if you could review the tests as I'm not 100% familiar with Mustella I'd
> appreciate it.
> 
Looks like the right pattern for testing methods.  Good job!

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


Re: DateField Issues and fixes

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

> Thanks.  Do you have time to add some more tests?
Added 40 odd tests to check various formats and check invalid inputs.

https://git-wip-us.apache.org/repos/asf?p=flex-sdk.git;a=commitdiff;h=531f7f2fe7aa72fa3c998d76c2de7b9b1761ee03

All test pass.

If anyone can suggest other tests go ahead and I'll add them.

Alex if you could review the tests as I'm not 100% familiar with Mustella I'd appreciate it.

Thanks,
Justin

Re: DateField Issues and fixes

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

> Thanks.  Do you have time to add some more tests?
Mastella test no as I'm not 100% familiar with them yet. 

I tested locally with about 50 combinations of formats and dates. I run against 4.9 and 4.10 and diffed the trace output to see what had changed.

Here the rough test code I used - it could be better but covers more ground that the existing tests :-) 

When I get some time I'll see if I can convert it into something mustella friendly.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()">
	
	<fx:Script>
		<![CDATA[
			import mx.controls.DateField;

			public function testStringToDate(date:String, format:String):void
			{
				var result:Date;
				
				try {
					result = DateField.stringToDate(date, format);
				}
				catch (error:Error) {
					trace("OPPS RTE! " + error.message);
				}
				
				if (result != null) {
					trace(date + " formatted with " + format + " = " + result.toString());
				}
				else {
					trace(date + " formatted with " + format + " = null");
				}		
			}
			
			public function testDateToString(date:Date, format:String):void
			{
				var result:String;
				
				try {
					result = DateField.dateToString(date, format);
				}
				catch (error:Error) {
					trace("OPPS RTE! " + error.message);
				}
				
				if (result != null) {
					trace(date + " formatted with " + format + " = " + result);
				}
				else {
					trace(date + " formatted with " + format + " = null");
				}		
			}
			
			
			protected function init():void
			{
				var result:Date;
				
				// MM/DD/YYYY
				testStringToDate("01 01 2013", "MM/DD/YYYY");
				testStringToDate("01/01/2013", "MM/DD/YYYY");
				testStringToDate("1/1/2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013", "MM/DD/YYYY");
				testStringToDate("30/1/2013", "MM/DD/YYYY");
				testStringToDate("7/17/69", "MM/DD/YYYY");
				testStringToDate("30/1/13", "MM/DD/YYYY");	
				testStringToDate("2013/1/1", "YYYY/M/DD")
				testStringToDate("13 6 2013", "DD MMM YYYY")
				
				testStringToDate("1/10", "MM/DD/YYYY");
				testStringToDate("2013", "MM/DD/YYYY");
				testStringToDate("1/1/10/2013", "MM/DD/YYYY");
				testStringToDate("13/10/2013", "MM/DD/YYYY");
				testStringToDate("1/45/2013", "MM/DD/YYYY");
				
				testStringToDate("1-10-2013", "MM/DD/YYYY");
				testStringToDate("1 10 2013", "MM/DD/YYYY");
				testStringToDate("1/10-2013", "MM/DD/YYYY");
				testStringToDate("1///10-2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013/", "MM/DD/YYYY");
				testStringToDate("/1/10/2013", "MM/DD/YYYY");
				testStringToDate("1////10//2013", "MM/DD/YYYY");
				testStringToDate("1    10  2013", "MM/DD/YYYY");

				// DD/MM/YYYY
				testStringToDate("01/01/2013", "DD/MM/YYYY");
				testStringToDate("1/1/2013", "DD/MM/YYYY");
				testStringToDate("1/10/2013", "DD/MM/YYYY");
				
				testStringToDate("1/10", "DD/MM/YYYY");
				testStringToDate("2013", "DD/MM/YYYY");
				testStringToDate("1/1/10/2013", "DD/MM/YYYY");
				
				testStringToDate("1-10-2013", "DD/MM/YYYY");
				testStringToDate("1 10 2013", "DD/MM/YYYY");
			
				// shorter formats
				testStringToDate("1/1/2013", "M/D/YYYY");
				testStringToDate("1/10/2013", "D/M/YY");
				testStringToDate("1/10/2013", "D/MM/YY");
				testStringToDate("1/10/2013", "M/D/YY");
				testStringToDate("7/17/69", "M/D/YY");
				testStringToDate("1/30/13", "M/D/YY");	
				testStringToDate("1/1/2013", "DD MMM YYYY");
			
				// missing parts
				testStringToDate("1/7/2013", "MM/DD");
				testStringToDate("1/1/2013","MM/YYYY");
				testStringToDate("1/7/2013", "M/D");	
				
				// No seperators (does this work?)
				testStringToDate("1/7/2013", "MMDD");
				testStringToDate("1/10/2013","MMDDYYYY");
				testStringToDate("1/7/2013", "DDMMYY");	
			
				// MM/DD/YYYY
				// MM/DD/YYYY
				testStringToDate("01 01 2013", "MM/DD/YYYY");
				testStringToDate("01/01/2013", "MM/DD/YYYY");
				testStringToDate("1/1/2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013", "MM/DD/YYYY");
				testStringToDate("30/1/2013", "MM/DD/YYYY");
				testStringToDate("7/17/69", "MM/DD/YYYY");
				testStringToDate("7/17/71", "MM/DD/YYYY");
				testStringToDate("1/1/13", "MM/DD/YYYY");			
				
				testStringToDate("1/10", "MM/DD/YYYY");
				testStringToDate("2013", "MM/DD/YYYY");
				testStringToDate("1/1/10/2013", "MM/DD/YYYY");
				testStringToDate("13/10/2013", "MM/DD/YYYY");
				testStringToDate("1/45/2013", "MM/DD/YYYY");
				
				testStringToDate("1-10-2013", "MM/DD/YYYY");
				testStringToDate("1 10 2013", "MM/DD/YYYY");
				testStringToDate("1/10-2013", "MM/DD/YYYY");
				testStringToDate("1///10-2013", "MM/DD/YYYY");
				testStringToDate("1/10/2013/", "MM/DD/YYYY");
				testStringToDate("/1/10/2013", "MM/DD/YYYY");
				testStringToDate("1////10//2013", "MM/DD/YYYY");
				testStringToDate("1    10  2013", "MM/DD/YYYY");
				
				// DD/MM/YYYY
				var date1:Date = new Date(2013,0,1);
				var date2:Date = new Date(2013,9,1);
				var date3:Date = new Date(1969,6,17);
				
				testDateToString(date1, "DD/MM/YYYY");
				testDateToString(date2, "DD/MM/YYYY");
				
				testDateToString(null, "DD/MM/YYYY");
				testDateToString(new Date(), "DD/MM/YYYY");
				testDateToString(new Date(Date.parse("")), "DD/MM/YYYY");
				
				// shorter formats
				testDateToString(date1, "M/D/YYYY");
				testDateToString(date2, "D/M/YY");
				testDateToString(date2, "D/MM/YY");
				testDateToString(date3, "M/D/YY");
				testDateToString(date3, "D/M/YY");
				testDateToString(date1, "M/D/YY");	
				
				// missing parts
				testDateToString(date2, "MM/DD");
				testDateToString(date2, "MM/YYYY");
				testDateToString(date2, "M/D");	
				
				// No seperators (does this work?)
				testDateToString(date2, "MMDD");
				testDateToString(date2, "MMDDYYYY");
				testDateToString(date2, "DDMMYY");	
			}
		]]>
	</fx:Script>
	
	<mx:DateField width="300" />
</s:Application>

Thanks,
Justin

Re: DateField Issues and fixes

Posted by Alex Harui <ah...@adobe.com>.
Thanks.  Do you have time to add some more tests?


On 4/18/13 8:42 PM, "Justin Mclean" <ju...@classsoftware.com> wrote:

> Hi,
> 
> I've been looking at DataField and it has a few problems mostly how it dealing
> with format string parsing in stringToDate and dateToString static methods.
> 
> There are several unresolved JIRA issues around this component.
> 
> Some of the issues include.
> 
> 1. Poor support of "M" and "D" vs "MM" and "DD". Currently:
> 1/10/2013 formatted with D/M/YY = null
> 1/10/2013 formatted with D/MM/YY = null
> 1/10/2013 formatted with M/D/YY = null
> 7/17/69 formatted with M/D/YY = null
> 1/30/13 formatted with M/D/YY = null
> 
> And also this - which is just plain wrong! It should either reject the format
> as being invalid or be able to deal with it.
> 
> Tue Oct 1 00:00:00 GMT+1000 2013 formatted with D/M/YY = 1/1013
> Thu Jul 17 00:00:00 GMT+1000 1969 formatted with M/D/YY = 7/1769
> Thu Jul 17 00:00:00 GMT+1000 1969 formatted with D/M/YY = 177/69
> Tue Oct 1 00:00:00 GMT+1000 2013 formatted with M/D = 1001
> 
> 2. Invalid formatting of invalid dates
> Invalid Date formatted with DD/MM/YYYY = NaN/NaN/NaN
> 
> 3. Magic cut off in 1970.
> 7/17/71 formatted with MM/DD/YYYY = Sat Jul 17 00:00:00 GMT+1000 1971
> 7/17/69 formatted with MM/DD/YYYY = Wed Jul 17 00:00:00 GMT+1100 2069
> 
> I've  rewritten the methods in a cleaner way that support a wider range of
> formats and fixes all the issue above.
> 
> The code is in the style of the existing SDK code (which is a little ugly
> IMO). Any feedback,potential bug etc etc would be appreciated.
> 
> There a bit more work to do with stringToDate and support for formats without
> separators - which might be tricky.
> 
> The mustella DateField tests all pass however I believe it only tests the US
> centric MM/DD/YYYY format.
> 
>      [java] =====================================================
>      [java]     Passes: 327
>      [java]     Fails: 0
>      [java] =====================================================
> 
> Thanks
> Justin
> 
> 
> 

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