You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2010/09/08 08:08:35 UTC

[jira] Updated: (LANG-645) FastDateFormat.format() outputs incorrect week of year because locale isn't respected

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

Henri Yandell updated LANG-645:
-------------------------------

    Fix Version/s: 3.0

Confirmed. The issue looks to be that when creating the GregorianCalendar in format(Date), the locale is not passed. 

> FastDateFormat.format() outputs incorrect week of year because locale isn't respected
> -------------------------------------------------------------------------------------
>
>                 Key: LANG-645
>                 URL: https://issues.apache.org/jira/browse/LANG-645
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 2.5
>         Environment: Ubuntu 10.04
> Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
> Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01, mixed mode)
> Commons Lang 2.5
>            Reporter: Mikael Uvebrandt
>             Fix For: 3.0
>
>
> FastDateFormat apparently doesn't respect the locale it was sent on creation when outputting week in year (e.g. "ww") in format(). It seems to use the settings of the system locale for firstDayOfWeek and minimalDaysInFirstWeek, which (depending on the year) may result in the incorrect week number being output.
> Here is a simple test program to demonstrate the problem by comparing with SimpleDateFormat, which gets the week number right:
> {code}
> import java.util.Calendar;
> import java.util.Date;
> import java.util.Locale;
> import java.text.SimpleDateFormat;
> import org.apache.commons.lang.time.FastDateFormat;
> public class FastDateFormatWeekBugDemo {
>     public static void main(String[] args) {
>         Locale.setDefault(new Locale("en", "US"));
>         Locale locale = new Locale("sv", "SE");
>         Calendar cal = Calendar.getInstance(); // setting locale here doesn't change outcome
>         cal.set(2010, 0, 1, 12, 0, 0);
>         Date d = cal.getTime();
>         System.out.println("Target date: " + d);
>         FastDateFormat fdf = FastDateFormat.getInstance("EEEE', week 'ww", locale);
>         SimpleDateFormat sdf = new SimpleDateFormat("EEEE', week 'ww", locale);
>         System.out.println("FastDateFormat:   " + fdf.format(d)); // will output "FastDateFormat:   fredag, week 01"
>         System.out.println("SimpleDateFormat: " + sdf.format(d)); // will output "SimpleDateFormat: fredag, week 53"
>     }
> }
> {code}
> If sv/SE is passed to Locale.setDefault() instead of en/US, both FastDateFormat and SimpleDateFormat output the correct week number.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.