From: <mu...@us...> - 2007-08-28 21:18:22
|
Revision: 165 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=165&view=rev Author: mungady Date: 2007-08-28 08:55:23 -0700 (Tue, 28 Aug 2007) Log Message: ----------- 2007-08-28 David Gilbert <dav...@ob...> * source/org/jfree/data/time/Week.java (Week(Date, TimeZone)): Deprecated, (Week(Date, TimeZone, Locale)): New constructor, * tests/org/jfree/data/time/junit/WeekTests.java (testConstructor): New test. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-08-28 15:55:23 UTC (rev 165) @@ -1,5 +1,13 @@ 2007-08-28 David Gilbert <dav...@ob...> + * source/org/jfree/data/time/Week.java + (Week(Date, TimeZone)): Deprecated, + (Week(Date, TimeZone, Locale)): New constructor, + * tests/org/jfree/data/time/junit/WeekTests.java + (testConstructor): New test. + +2007-08-28 David Gilbert <dav...@ob...> + * source/org/jfree/chart/renderer/category/StatisticalBarRenderer.java (drawHorizontalItem): Check for null data items, (drawVerticalItem): Likewise, Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/Week.java 2007-08-28 15:55:23 UTC (rev 165) @@ -65,6 +65,8 @@ * 05-Oct-2006 : Updated API docs (DG); * 06-Oct-2006 : Refactored to cache first and last millisecond values (DG); * 09-Jan-2007 : Fixed bug in next() (DG); + * 28-Aug-2007 : Added new constructor to avoid problem in creating new + * instances (DG); * */ @@ -73,6 +75,7 @@ import java.io.Serializable; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.TimeZone; /** @@ -156,7 +159,7 @@ */ public Week(Date time) { // defer argument checking... - this(time, RegularTimePeriod.DEFAULT_TIME_ZONE); + this(time, RegularTimePeriod.DEFAULT_TIME_ZONE, Locale.getDefault()); } /** @@ -165,15 +168,35 @@ * * @param time the date/time (<code>null</code> not permitted). * @param zone the time zone (<code>null</code> not permitted). + * + * @deprecated As of 1.0.7, use {@link #Week(Date, TimeZone, Locale)}. */ public Week(Date time, TimeZone zone) { + // defer argument checking... + this(time, RegularTimePeriod.DEFAULT_TIME_ZONE, Locale.getDefault()); + } + + /** + * Creates a time period for the week in which the specified date/time + * falls, calculated relative to the specified time zone. + * + * @param time the date/time (<code>null</code> not permitted). + * @param zone the time zone (<code>null</code> not permitted). + * @param locale the locale (<code>null</code> not permitted). + * + * @since 1.0.7 + */ + public Week(Date time, TimeZone zone, Locale locale) { if (time == null) { throw new IllegalArgumentException("Null 'time' argument."); } if (zone == null) { throw new IllegalArgumentException("Null 'zone' argument."); } - Calendar calendar = Calendar.getInstance(zone); + if (locale == null) { + throw new IllegalArgumentException("Null 'locale' argument."); + } + Calendar calendar = Calendar.getInstance(zone, locale); calendar.setTime(time); // sometimes the last few days of the year are considered to fall in @@ -197,7 +220,6 @@ this.year = (short) yyyy; } peg(calendar); - } /** @@ -522,8 +544,7 @@ w = Week.stringToWeek(s2); if (w == -1) { throw new TimePeriodFormatException( - "Can't evaluate the week." - ); + "Can't evaluate the week."); } result = new Week(w, y); } @@ -533,23 +554,20 @@ w = Week.stringToWeek(s1); if (w == -1) { throw new TimePeriodFormatException( - "Can't evaluate the week." - ); + "Can't evaluate the week."); } result = new Week(w, y); } else { throw new TimePeriodFormatException( - "Can't evaluate the year." - ); + "Can't evaluate the year."); } } } else { throw new TimePeriodFormatException( - "Could not find separator." - ); + "Could not find separator."); } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-08-28 11:53:09 UTC (rev 164) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/WeekTests.java 2007-08-28 15:55:23 UTC (rev 165) @@ -44,6 +44,7 @@ * 06-Apr-2006 : Added testBug1448828() method (DG); * 01-Jun-2006 : Added testBug1498805() method (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); + * 28-Aug-2007 : Added test for constructor problem (DG); * */ @@ -185,7 +186,7 @@ in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(w1, w2); @@ -463,4 +464,42 @@ Locale.setDefault(saved); } + /** + * A test for a problem in constructing a new Week instance. + */ + public void testConstructor() { + Locale savedLocale = Locale.getDefault(); + TimeZone savedZone = TimeZone.getDefault(); + Locale.setDefault(new Locale("da", "DK")); + TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); + GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance( + TimeZone.getDefault(), Locale.getDefault()); + + // first day of week is monday + assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); + cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + Date t = cal.getTime(); + Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); + assertEquals(34, w.getWeek()); + + Locale.setDefault(Locale.US); + TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); + cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); + // first day of week is Sunday + assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); + cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); + cal.set(Calendar.MILLISECOND, 0); + + t = cal.getTime(); + w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen")); + assertEquals(35, w.getWeek()); + w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), + new Locale("da", "DK")); + assertEquals(34, w.getWeek()); + + Locale.setDefault(savedLocale); + TimeZone.setDefault(savedZone); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |