Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 56361 invoked from network); 8 Sep 2010 06:11:20 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Sep 2010 06:11:20 -0000 Received: (qmail 92762 invoked by uid 500); 8 Sep 2010 06:11:20 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 92270 invoked by uid 500); 8 Sep 2010 06:11:18 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 92211 invoked by uid 99); 8 Sep 2010 06:11:15 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Sep 2010 06:11:15 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Sep 2010 06:10:56 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o886AZTj028784 for ; Wed, 8 Sep 2010 06:10:35 GMT Message-ID: <11062398.70401283926235048.JavaMail.jira@thor> Date: Wed, 8 Sep 2010 02:10:35 -0400 (EDT) From: "Henri Yandell (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (LANG-645) FastDateFormat.format() outputs incorrect week of year because locale isn't respected In-Reply-To: <23662459.469401282313536988.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LANG-645?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Henri Yandell updated LANG-645: ------------------------------- Attachment: LANG-645.patch > 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 > > Attachments: LANG-645.patch > > > 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.