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
Original issue reported on code.google.com by
chadtaka...@gmail.com
on 31 Oct 2008 at 1:38