You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2016/05/25 07:01:13 UTC

[jira] [Updated] (BEANUTILS-486) DateConverter fails when pattern and locale are set

     [ https://issues.apache.org/jira/browse/BEANUTILS-486?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary Gregory updated BEANUTILS-486:
-----------------------------------
    Description: 
When using a DateConverter or any of the date conversion classes, setting an explicit pattern causes the locale to be ignored. The converter seems to think that the locale is only useful for finding the default pattern for the locale, but that's not true, as the following code illustrates.

{code:java}
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy", new Locale("en_US"));
        ParsePosition pos = new ParsePosition(0);
        Date result = sdf.parse("Dec 15, 1978", pos);
        System.out.println(result); // Prints "Fri Dec 15 00:00:00 CET 1978"
        
        // Equivalent code should return the same result as the last section
        DateConverter c = new DateConverter();
        c.setPattern("MMM dd, yyyy");
        c.setLocale(new Locale("en_US"));
        c.convert(Date.class, "Dec 15, 1978"); // Throws ConversionException
    }
{code}

I'm expanding opencsv (opencsv.sourceforge.net), and this bug is breaking my code. I would really appreciate a speedy resolution.

  was:
When using a DateConverter or any of the date conversion classes, setting an explicit pattern causes the locale to be ignored. The converter seems to think that the locale is only useful for finding the default pattern for the locale, but that's not true, as the following code illustrates.

    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy", new Locale("en_US"));
        ParsePosition pos = new ParsePosition(0);
        Date result = sdf.parse("Dec 15, 1978", pos);
        System.out.println(result); // Prints "Fri Dec 15 00:00:00 CET 1978"
        
        // Equivalent code should return the same result as the last section
        DateConverter c = new DateConverter();
        c.setPattern("MMM dd, yyyy");
        c.setLocale(new Locale("en_US"));
        c.convert(Date.class, "Dec 15, 1978"); // Throws ConversionException
    }

I'm expanding opencsv (opencsv.sourceforge.net), and this bug is breaking my code. I would really appreciate a speedy resolution.


> DateConverter fails when pattern and locale are set
> ---------------------------------------------------
>
>                 Key: BEANUTILS-486
>                 URL: https://issues.apache.org/jira/browse/BEANUTILS-486
>             Project: Commons BeanUtils
>          Issue Type: Bug
>          Components: Locale BeanUtils / Converters
>    Affects Versions: 1.9.2
>         Environment: MacOS X 10.11.4
> Java 1.8.0_11
> Default locale: de_DE
>            Reporter: Andrew Rucker Jones
>              Labels: easyfix
>
> When using a DateConverter or any of the date conversion classes, setting an explicit pattern causes the locale to be ignored. The converter seems to think that the locale is only useful for finding the default pattern for the locale, but that's not true, as the following code illustrates.
> {code:java}
>     public static void main(String[] args) {
>         SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy", new Locale("en_US"));
>         ParsePosition pos = new ParsePosition(0);
>         Date result = sdf.parse("Dec 15, 1978", pos);
>         System.out.println(result); // Prints "Fri Dec 15 00:00:00 CET 1978"
>         
>         // Equivalent code should return the same result as the last section
>         DateConverter c = new DateConverter();
>         c.setPattern("MMM dd, yyyy");
>         c.setLocale(new Locale("en_US"));
>         c.convert(Date.class, "Dec 15, 1978"); // Throws ConversionException
>     }
> {code}
> I'm expanding opencsv (opencsv.sourceforge.net), and this bug is breaking my code. I would really appreciate a speedy resolution.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)