#8 Add Locale to ParseDate-Constructor

2.1.0
closed
None
5
2013-04-24
2009-03-03
No

Thanks for a great CSV parser!
Here's my feature request, I'll start with my use case:

I am parsing Dates in the format "Tue Oct 4 09:34:02 2005". This translates to "new ParseDate("E MMM dd HH:mm:ss yyyy")".
This would work fine on a machine with the locale set to English/US. However if the locale is set to something else (german in my case) you'll get parse exceptions because 'Tue' is not a day in german.

One would have the same problem if you wanted to parse a german date on a US/UK machine.

There are three solutions to this problem:
1) I write my own Processor that takes a Locale as additional argument(easy but custom solution)
2) I call Locale.setDefault(Locale.ENGLISH) and change it back after reading. However this is a global fix and may cause trouble if other code is running concurrently. Dirty.
3) The existing ParseDate gets a second optional parameter (Locale) which tells SuperCSV what Locale it should assume for the input data.

IMHO Locale support should be part of the library and added it possible.

If I have the time I'll write a patch for this issue.

Discussion

  • Kasper B. Graversen

    thanks for the patch..

     
  • James Bassett

    James Bassett - 2011-11-16

    This was closed but never added! I'll put it in the next release.

     
  • James Bassett

    James Bassett - 2012-09-17

    We never ended up adding this in 2.0.0-beta-1, and while solution 3 seems fine, I think we should consider adding a locale preference to CsvPreference. That way all locale-dependent processors can make use of it. Unfortunately, cell processors currently have no access to the preferences - it might make sense to add the preferences to the CsvContext (which they do have access to), but this will also require a few changes.

     
  • Kasper B. Graversen

    I think local may be important in parsing decimal numbers and dates.
    But for most processors, the preferecens are unimportant. Maybe those
    two processors could take as an optional argument, the preferences,
    and if present during the execution of the processor use said prefs..

    -k

    On Mon, Sep 17, 2012 at 10:18 AM, James Bassett
    jamesbassett@users.sf.net wrote:

    We never ended up adding this in 2.0.0-beta-1, and while solution 3 seems
    fine, I think we should consider adding a locale preference to
    CsvPreference. That way all locale-dependent processors can make use of it.
    Unfortunately, cell processors currently have no access to the preferences -
    it might make sense to add the preferences to the CsvContext (which they do
    have access to), but this will also require a few changes.


    feature-requests:8 Add Locale to ParseDate-Constructor

    Status: open Created: Tue Mar 03, 2009 09:26 AM UTC by Rolf Wojtech Last
    Updated: Fri Sep 14, 2012 08:42 PM UTC Owner: James Bassett

    Thanks for a great CSV parser!
    Here's my feature request, I'll start with my use case:

    I am parsing Dates in the format "Tue Oct 4 09:34:02 2005". This translates
    to "new ParseDate("E MMM dd HH:mm:ss yyyy")".
    This would work fine on a machine with the locale set to English/US. However
    if the locale is set to something else (german in my case) you'll get parse
    exceptions because 'Tue' is not a day in german.

    One would have the same problem if you wanted to parse a german date on a
    US/UK machine.

    There are three solutions to this problem:
    1) I write my own Processor that takes a Locale as additional argument(easy
    but custom solution)
    2) I call Locale.setDefault(Locale.ENGLISH) and change it back after
    reading. However this is a global fix and may cause trouble if other code is
    running concurrently. Dirty.
    3) The existing ParseDate gets a second optional parameter (Locale) which
    tells SuperCSV what Locale it should assume for the input data.

    IMHO Locale support should be part of the library and added it possible.

    If I have the time I'll write a patch for this issue.


    Sent from sourceforge.net because you indicated interest in
    https://sourceforge.net/p/supercsv/feature-requests/8/

    To unsubscribe from further messages, please visit
    https://sourceforge.net/auth/prefs/

    --
    -Kasper

     
  • James Bassett

    James Bassett - 2013-01-11
    • status: open --> pending
    • milestone: --> 2.1.0
     
  • James Bassett

    James Bassett - 2013-01-11

    Added for 2.1.0 (finally!)
    [r271]

     

    Related

    Commit: [r271]

  • James Bassett

    James Bassett - 2013-04-24
    • Status: pending --> closed
     

Log in to post a comment.