commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (BEANUTILS-486) DateConverter fails when pattern and locale are set
Date Wed, 25 May 2016 07:02:12 GMT

    [ https://issues.apache.org/jira/browse/BEANUTILS-486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15299578#comment-15299578
] 

Gary Gregory commented on BEANUTILS-486:
----------------------------------------

Patches welcome, with unit tests of course! :-)

> 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)

Mime
View raw message