You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-dev@incubator.apache.org by Yee-wah Lee <ye...@oracle.com> on 2007/03/09 00:39:31 UTC

tr:datetimeconverter and shortish style

Hi all,

I see the following code in the (server-side) DateTimeConverter and 
think it may be problematic.

1) The default style for dates is set to shortish, which forces the year 
pattern to be at least 4 digits 
(http://incubator.apache.org/adffaces/trinidad-api/apidocs/org/apache/myfaces/trinidad/convert/DateTimeConverter.html)
/New dateStyle |shortish| has been introduced. Shortish is identical to 
|short| but forces the year to be a full four digits. If dateStyle is 
not set, then |dateStyle| defaults to |shortish|.
/
2) Accordingly, the converter sets the pattern on its DateFormat to use 
at least 4 digits, if 'y' appears at all. The method is _get4YearFormat()

3) Now, the Javadoc states this for SimpleDateFormat 
(http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html)
/For parsing, if the number of pattern letters is more than 2, the year 
is interpreted literally, regardless of the number of digits. So using 
the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
/
So why I think this is a problem:

    *  From the user's perspective, if they enters a date like
      '1/31/07', it becomes January 31st, 7 A.D rather than the (more
      likely intended) January 31st, 2007.
    *  It also seems like the code intends otherwise, because it also
      calls DateFormat's set2DigitYearStart() which is intended for
      parsing 2 digit years.

Does anyone have more background on this? I was able to reproduce the 
behavior using an inputText bound to a backing Date value, and a 
DateTimeConverter attached to it.

Thanks,
Yee-Wah


Re: tr:datetimeconverter and shortish style

Posted by Matthias Wessendorf <ma...@apache.org>.
fine w/ me

-M

On 3/22/07, Gabrielle Crawford <ga...@oracle.com> wrote:
> This seems like a fine fix, I will merge this unless there are objections.
>
> Thanks,
>
> Gab
>
> On 3/15/2007 3:12 PM, Yee-wah Lee wrote:
>
> >
> > I've filed JIRA ADF-Faces 410 on this:
> > https://issues.apache.org/jira/browse/ADFFACES-410
> >
> > In there I suggest a fix to use the 4-digit pattern when formatting,
> > but the 2-digit pattern when parsing. That involves adding a param to
> > the protected method getDateFormat(..boolean forParsing), and using
> > that param to determine when to run "_get4YearFormat()" which fixes up
> > the DateFormat object.
> > Please let me know/comment on the JIRA if you see any issues.
> >
> > Thanks,
> > Yee-Wah
> >
> > On 3/9/2007 11:30 AM PST, Adam Winer wrote:
> >
> >> The intent of the code is absolutely to use the two-digit
> >> year start to handle two-digits entries.  If that isn't happening,
> >> it's a pretty bad bug.
> >>
> >> -- Adam
> >>
> >>
> >> On 3/8/07, Yee-wah Lee <ye...@oracle.com> wrote:
> >>
> >>> Hi all,
> >>>
> >>> I see the following code in the (server-side) DateTimeConverter and
> >>> think it may be problematic.
> >>>
> >>> 1) The default style for dates is set to shortish, which forces the
> >>> year
> >>> pattern to be at least 4 digits
> >>> (http://incubator.apache.org/adffaces/trinidad-api/apidocs/org/apache/myfaces/trinidad/convert/DateTimeConverter.html)
> >>>
> >>> /New dateStyle |shortish| has been introduced. Shortish is identical to
> >>> |short| but forces the year to be a full four digits. If dateStyle is
> >>> not set, then |dateStyle| defaults to |shortish|.
> >>> /
> >>> 2) Accordingly, the converter sets the pattern on its DateFormat to use
> >>> at least 4 digits, if 'y' appears at all. The method is
> >>> _get4YearFormat()
> >>>
> >>> 3) Now, the Javadoc states this for SimpleDateFormat
> >>> (http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html)
> >>>
> >>> /For parsing, if the number of pattern letters is more than 2, the year
> >>> is interpreted literally, regardless of the number of digits. So using
> >>> the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
> >>> /
> >>> So why I think this is a problem:
> >>>
> >>>     *  From the user's perspective, if they enters a date like
> >>>       '1/31/07', it becomes January 31st, 7 A.D rather than the (more
> >>>       likely intended) January 31st, 2007.
> >>>     *  It also seems like the code intends otherwise, because it also
> >>>       calls DateFormat's set2DigitYearStart() which is intended for
> >>>       parsing 2 digit years.
> >>>
> >>> Does anyone have more background on this? I was able to reproduce the
> >>> behavior using an inputText bound to a backing Date value, and a
> >>> DateTimeConverter attached to it.
> >>>
> >>> Thanks,
> >>> Yee-Wah
> >>>
> >>>
>


-- 
Matthias Wessendorf
http://tinyurl.com/fmywh

further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com

Re: tr:datetimeconverter and shortish style

Posted by Gabrielle Crawford <ga...@oracle.com>.
This seems like a fine fix, I will merge this unless there are objections.

Thanks,

Gab

On 3/15/2007 3:12 PM, Yee-wah Lee wrote:

>
> I've filed JIRA ADF-Faces 410 on this:
> https://issues.apache.org/jira/browse/ADFFACES-410
>
> In there I suggest a fix to use the 4-digit pattern when formatting, 
> but the 2-digit pattern when parsing. That involves adding a param to 
> the protected method getDateFormat(..boolean forParsing), and using 
> that param to determine when to run "_get4YearFormat()" which fixes up 
> the DateFormat object.
> Please let me know/comment on the JIRA if you see any issues.
>
> Thanks,
> Yee-Wah
>
> On 3/9/2007 11:30 AM PST, Adam Winer wrote:
>
>> The intent of the code is absolutely to use the two-digit
>> year start to handle two-digits entries.  If that isn't happening,
>> it's a pretty bad bug.
>>
>> -- Adam
>>
>>
>> On 3/8/07, Yee-wah Lee <ye...@oracle.com> wrote:
>>
>>> Hi all,
>>>
>>> I see the following code in the (server-side) DateTimeConverter and
>>> think it may be problematic.
>>>
>>> 1) The default style for dates is set to shortish, which forces the 
>>> year
>>> pattern to be at least 4 digits
>>> (http://incubator.apache.org/adffaces/trinidad-api/apidocs/org/apache/myfaces/trinidad/convert/DateTimeConverter.html) 
>>>
>>> /New dateStyle |shortish| has been introduced. Shortish is identical to
>>> |short| but forces the year to be a full four digits. If dateStyle is
>>> not set, then |dateStyle| defaults to |shortish|.
>>> /
>>> 2) Accordingly, the converter sets the pattern on its DateFormat to use
>>> at least 4 digits, if 'y' appears at all. The method is 
>>> _get4YearFormat()
>>>
>>> 3) Now, the Javadoc states this for SimpleDateFormat
>>> (http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html) 
>>>
>>> /For parsing, if the number of pattern letters is more than 2, the year
>>> is interpreted literally, regardless of the number of digits. So using
>>> the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
>>> /
>>> So why I think this is a problem:
>>>
>>>     *  From the user's perspective, if they enters a date like
>>>       '1/31/07', it becomes January 31st, 7 A.D rather than the (more
>>>       likely intended) January 31st, 2007.
>>>     *  It also seems like the code intends otherwise, because it also
>>>       calls DateFormat's set2DigitYearStart() which is intended for
>>>       parsing 2 digit years.
>>>
>>> Does anyone have more background on this? I was able to reproduce the
>>> behavior using an inputText bound to a backing Date value, and a
>>> DateTimeConverter attached to it.
>>>
>>> Thanks,
>>> Yee-Wah
>>>
>>>

Re: tr:datetimeconverter and shortish style

Posted by Yee-wah Lee <ye...@oracle.com>.
I've filed JIRA ADF-Faces 410 on this:
https://issues.apache.org/jira/browse/ADFFACES-410

In there I suggest a fix to use the 4-digit pattern when formatting, but 
the 2-digit pattern when parsing. That involves adding a param to the 
protected method getDateFormat(..boolean forParsing), and using that 
param to determine when to run "_get4YearFormat()" which fixes up the 
DateFormat object. 

Please let me know/comment on the JIRA if you see any issues.

Thanks,
Yee-Wah

On 3/9/2007 11:30 AM PST, Adam Winer wrote:
> The intent of the code is absolutely to use the two-digit
> year start to handle two-digits entries.  If that isn't happening,
> it's a pretty bad bug.
>
> -- Adam
>
>
> On 3/8/07, Yee-wah Lee <ye...@oracle.com> wrote:
>> Hi all,
>>
>> I see the following code in the (server-side) DateTimeConverter and
>> think it may be problematic.
>>
>> 1) The default style for dates is set to shortish, which forces the year
>> pattern to be at least 4 digits
>> (http://incubator.apache.org/adffaces/trinidad-api/apidocs/org/apache/myfaces/trinidad/convert/DateTimeConverter.html) 
>>
>> /New dateStyle |shortish| has been introduced. Shortish is identical to
>> |short| but forces the year to be a full four digits. If dateStyle is
>> not set, then |dateStyle| defaults to |shortish|.
>> /
>> 2) Accordingly, the converter sets the pattern on its DateFormat to use
>> at least 4 digits, if 'y' appears at all. The method is 
>> _get4YearFormat()
>>
>> 3) Now, the Javadoc states this for SimpleDateFormat
>> (http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html) 
>>
>> /For parsing, if the number of pattern letters is more than 2, the year
>> is interpreted literally, regardless of the number of digits. So using
>> the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
>> /
>> So why I think this is a problem:
>>
>>     *  From the user's perspective, if they enters a date like
>>       '1/31/07', it becomes January 31st, 7 A.D rather than the (more
>>       likely intended) January 31st, 2007.
>>     *  It also seems like the code intends otherwise, because it also
>>       calls DateFormat's set2DigitYearStart() which is intended for
>>       parsing 2 digit years.
>>
>> Does anyone have more background on this? I was able to reproduce the
>> behavior using an inputText bound to a backing Date value, and a
>> DateTimeConverter attached to it.
>>
>> Thanks,
>> Yee-Wah
>>
>>

Re: tr:datetimeconverter and shortish style

Posted by Adam Winer <aw...@gmail.com>.
The intent of the code is absolutely to use the two-digit
year start to handle two-digits entries.  If that isn't happening,
it's a pretty bad bug.

-- Adam


On 3/8/07, Yee-wah Lee <ye...@oracle.com> wrote:
> Hi all,
>
> I see the following code in the (server-side) DateTimeConverter and
> think it may be problematic.
>
> 1) The default style for dates is set to shortish, which forces the year
> pattern to be at least 4 digits
> (http://incubator.apache.org/adffaces/trinidad-api/apidocs/org/apache/myfaces/trinidad/convert/DateTimeConverter.html)
> /New dateStyle |shortish| has been introduced. Shortish is identical to
> |short| but forces the year to be a full four digits. If dateStyle is
> not set, then |dateStyle| defaults to |shortish|.
> /
> 2) Accordingly, the converter sets the pattern on its DateFormat to use
> at least 4 digits, if 'y' appears at all. The method is _get4YearFormat()
>
> 3) Now, the Javadoc states this for SimpleDateFormat
> (http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html)
> /For parsing, if the number of pattern letters is more than 2, the year
> is interpreted literally, regardless of the number of digits. So using
> the pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
> /
> So why I think this is a problem:
>
>     *  From the user's perspective, if they enters a date like
>       '1/31/07', it becomes January 31st, 7 A.D rather than the (more
>       likely intended) January 31st, 2007.
>     *  It also seems like the code intends otherwise, because it also
>       calls DateFormat's set2DigitYearStart() which is intended for
>       parsing 2 digit years.
>
> Does anyone have more background on this? I was able to reproduce the
> behavior using an inputText bound to a backing Date value, and a
> DateTimeConverter attached to it.
>
> Thanks,
> Yee-Wah
>
>