marcomachadosantos / gwt-chronoscope

Automatically exported from code.google.com/p/gwt-chronoscope
GNU Lesser General Public License v2.1
0 stars 0 forks source link

In some cases, FastChronoDate throws runtime exception when setting the constituent fields in the wrong order #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Consider the case where a ChronoDate object is set to the date 'January 31, 
2007'.  Suppose we 
wanted to change this date's state to 'February 28, 2007'.  The following code 
throws an 
exception at line 2:

    line 1: ChronoDate d = ChronoDate.get(2007, Calendar.JANUARY, 31);
    line 2: d.set(TimeUnit.MONTH, Calendar.FEBRUARY);
    line 3: d.set(TimeUnit.DAY, 28);

The error occurs because each set() method attempts to validate the complete 
date, so in line 2, 
the state is 'February 31, 2007' (because the day has not yet been set to the 
28th), and this is an 
invalid date value.

The proposed solution is to modify the set() mutator method to use method 
chaining, so that the 
client code can set the desired fields and then signal that the "transaction" 
is done, at which 
point date validation would occur.  The following code example modifies the 
date using the 
method chaining syntax:

    line 1: ChronoDate d = ChronoDate.get(2007, Calendar.JANUARY, 31);
    line 2: d.set().month(Calendar.FEBRUARY).day(28).done();

Original issue reported on code.google.com by chadtaka...@gmail.com on 31 Oct 2008 at 1:38

GoogleCodeExporter commented 9 years ago
Resolved in r689.

Original comment by chadtaka...@gmail.com on 31 Oct 2008 at 3:08