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/18 06:28:50 UTC

Interesting code in DateField

Hi,

Funny little assumption in DateField's stringToDate function:

        if (yearString.length == 2 && yearNum < 70)
            yearNum+=2000;

So if you enter a two digit year 70 or above it thinks it's 1st century AD (?) and below 70 and it's the 21st century! Just what you need for date of birth fields :-)

I think more reasonable way of doing this is have a defaultCentury and set that to 1900 or 2000? Any other ideas?

Thanks,
Justin

Re: Interesting code in DateField

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

> I guess it's assuming all years are 4 digit and not 2 digit.
You might think so but the year can be a 2 or 4 digits string at this point. I think there is some confusion there with the 1 Jan 1970 date (as you pointed out) but it's for the wrong reason :-)

Thanks,
Justin

RE: Interesting code in DateField

Posted by Kessler CTR Mark J <ma...@usmc.mil>.
I guess it's assuming all years are 4 digit and not 2 digit.  The date [1970 Jan 1] is the date I believe is a lot of date/time numbers are based on for the start.  So it maybe this is ultimately saying if it's a two digit year and it's before January 1st 1970 they must mean the year 2000?


-Mark


-----Original Message-----
From: Justin Mclean [mailto:justin@classsoftware.com] 
Sent: Thursday, April 18, 2013 12:29 AM
To: dev@flex.apache.org
Subject: Interesting code in DateField

Hi,

Funny little assumption in DateField's stringToDate function:

        if (yearString.length == 2 && yearNum < 70)
            yearNum+=2000;

So if you enter a two digit year 70 or above it thinks it's 1st century AD (?) and below 70 and it's the 21st century! Just what you need for date of birth fields :-)

I think more reasonable way of doing this is have a defaultCentury and set that to 1900 or 2000? Any other ideas?

Thanks,
Justin