From owner-freebsd-java@FreeBSD.ORG Tue May 30 13:53:47 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 27B2D16A473 for ; Tue, 30 May 2006 13:53:46 +0000 (UTC) (envelope-from past@ebs.gr) Received: from fly.ebs.gr (fly.ebs.gr [83.171.239.113]) by mx1.FreeBSD.org (Postfix) with ESMTP id 57C5043D46 for ; Tue, 30 May 2006 13:53:44 +0000 (GMT) (envelope-from past@ebs.gr) Received: from ebs.gr (root@hal.ebs.gr [10.1.1.2]) by fly.ebs.gr (8.12.9p1/8.12.9) with ESMTP id k4UDrgGP041795; Tue, 30 May 2006 16:53:42 +0300 (EEST) (envelope-from past@ebs.gr) Received: from [10.1.1.185] (pc185.ebs.gr [10.1.1.185]) by ebs.gr (8.13.3/8.13.3) with ESMTP id k4UDrfEj065338; Tue, 30 May 2006 16:53:42 +0300 (EEST) (envelope-from past@ebs.gr) Received: from 127.0.0.1 (AVG SMTP 7.1.394 [268.7.4/351]); Tue, 30 May 2006 16:53:40 +0300 Message-ID: <447C4E64.8030604@ebs.gr> Date: Tue, 30 May 2006 16:53:40 +0300 From: Panagiotis Astithas Organization: EBS Ltd. User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 To: Heiko Weber References: <200605291720.19793.java@wecos.de> <447BE408.8040504@ebs.gr> <200605301000.35042.java@wecos.de> <200605301532.30185.java@wecos.de> In-Reply-To: <200605301532.30185.java@wecos.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-java@freebsd.org Subject: Re: Calendar Question - maybe bug ? X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 May 2006 13:54:26 -0000 Heiko Weber wrote: > Am Dienstag, 30. Mai 2006 10:00 schrieb Heiko Weber: >> Am Dienstag, 30. Mai 2006 08:19 schrieb Panagiotis Astithas: >>> Heiko Weber wrote: >>>> Hi ! >>>> >>>> I've a problem with GregorianCalendar, which returns different weeks >>>> (in year) on FreeBSD 6.1, java version is >>>> >>>> # java -version >>>> Java HotSpot(TM) Server VM (build 1.5.0-p2-heiko_03_jan_2006_23_51, >>>> mixed mode) >>>> >>>> Test program (A.java): >>>> >>>> import java.util.Calendar; >>>> import java.util.GregorianCalendar; >>>> >>>> public class A { >>>> public static int weeksInYear(int year) { >>>> Calendar cal = GregorianCalendar.getInstance(); >>>> >>>> cal.set(year, 11, 31); >>>> >>>> return cal.get(Calendar.WEEK_OF_YEAR) == 53 ? 53 : 52; >>>> } >>>> >>>> public static void main(String args[]) { >>>> for (int i = 1990; i <= 2006; i++) >>>> System.out.println("Weeks in Year " + i + " = " >>>> + weeksInYear(i)); >>>> } >>>> } >>>> >>>> Output on a Linux or Windows JRE is: >>>> >>>> Weeks in Year 1990 = 52 >>>> Weeks in Year 1991 = 52 >>>> Weeks in Year 1992 = 53 >>>> Weeks in Year 1993 = 52 >>>> Weeks in Year 1994 = 52 >>>> Weeks in Year 1995 = 52 >>>> Weeks in Year 1996 = 52 >>>> Weeks in Year 1997 = 52 >>>> Weeks in Year 1998 = 53 >>>> Weeks in Year 1999 = 52 >>>> Weeks in Year 2000 = 52 >>>> Weeks in Year 2001 = 52 >>>> Weeks in Year 2002 = 52 >>>> Weeks in Year 2003 = 52 >>>> Weeks in Year 2004 = 53 >>>> Weeks in Year 2005 = 52 >>>> Weeks in Year 2006 = 52 >>>> >>>> Output on FreeBSD is: >>>> >>>> Weeks in Year 1990 = 52 >>>> Weeks in Year 1991 = 52 >>>> Weeks in Year 1992 = 52 >>>> Weeks in Year 1993 = 52 >>>> Weeks in Year 1994 = 53 >>>> Weeks in Year 1995 = 52 >>>> Weeks in Year 1996 = 52 >>>> Weeks in Year 1997 = 52 >>>> Weeks in Year 1998 = 52 >>>> Weeks in Year 1999 = 52 >>>> Weeks in Year 2000 = 52 >>>> Weeks in Year 2001 = 52 >>>> Weeks in Year 2002 = 52 >>>> Weeks in Year 2003 = 52 >>>> Weeks in Year 2004 = 52 >>>> Weeks in Year 2005 = 53 >>>> Weeks in Year 2006 = 52 >>>> >>>> Is this my fault or would it help to update the FreeBSD JRE ? Or is the >>>> java-Calendar-System build up on some local (changeable) settings ? >>>> >>>> Thanks for any help or hint. >>> I can't replicate this here on either diablo-jdk15 or jdk15 patchset 2 >>> (as yours). Is your systems time/timezone/etc. correct? >> Hm, /etc/localtime has been installed last year in september - from >> installation of FreeBSD 6.0. If I remember correct I used sysinstall and >> answered "cmos time == local time". >> >> # date >> Tue May 30 09:48:36 CEST 2006 >> >> Is this ok for germany ? >> >> At the moment I compile jdk with patchset 3 on an other FreeBSD system to >> verify ... there I can play with the timezone settings after installation. >> > > Ah, got some light: > > if I change > > Calendar cal = GregorianCalendar.getInstance(); > > to > > Calendar cal = new GregorianCalendar( > TimeZone.getTimeZone("CEST"), new Locale("DE")); > > I get better results: > > 31.12.1990 is week #1 / year 1990 has 52 weeks > 31.12.1991 is week #1 / year 1991 has 52 weeks > 31.12.1992 is week #53 / year 1992 has 53 weeks > 31.12.1993 is week #52 / year 1993 has 52 weeks > 31.12.1994 is week #52 / year 1994 has 52 weeks > 31.12.1995 is week #52 / year 1995 has 52 weeks > 31.12.1996 is week #1 / year 1996 has 52 weeks > 31.12.1997 is week #1 / year 1997 has 52 weeks > 31.12.1998 is week #53 / year 1998 has 53 weeks > 31.12.1999 is week #52 / year 1999 has 52 weeks > 31.12.2000 is week #52 / year 2000 has 52 weeks > 31.12.2001 is week #1 / year 2001 has 52 weeks > 31.12.2002 is week #1 / year 2002 has 52 weeks > 31.12.2003 is week #1 / year 2003 has 52 weeks > 31.12.2004 is week #53 / year 2004 has 53 weeks > 31.12.2005 is week #52 / year 2005 has 52 weeks > 31.12.2006 is week #52 / year 2006 has 52 weeks > > Maybe there is a problem getting the "default" Locale and/or Timezone. > > I changed the line to > > Calendar cal = new GregorianCalendar(TimeZone.getDefault(), new Locale("DE")); > > looks good - results are ok. And > > Calendar cal = new GregorianCalendar( > TimeZone.getTimeZone("CEST"), Locale.getDefault()); > > Looks bad, problem is the default Locale. But how to fix this in FreeBSD, is > there a file in /etc/ which contains a default ? "locale" reports: > > # locale > LANG= > LC_CTYPE="C" > LC_COLLATE="C" > LC_TIME="C" > LC_NUMERIC="C" > LC_MONETARY="C" > LC_MESSAGES="C" > LC_ALL= > > with > > # setenv LANG de_DE.ISO8859-1 > > this could be fixed - and my test program works ! Now looking for a good place > where to set "LANG" system wide ... Right, using the same locale settings on Linux gives the same results as FreeBSD. The best place to set LANG would be /etc/login.conf, unless you have other requirements. Cheers, Panagiotis