-
Enhancement
-
Resolution: Future Project
-
P4
-
None
-
1.2.0, 1.3.0, 1.4.0, 5.0
-
generic, x86, sparc
-
generic, solaris_9, windows_nt, windows_xp
The class should be replaced with two separate classes/interfaces that encapsulate either state or mapping. CalendarDate would encapsulate a calendar-dependent representation of a point in time using multiple fields - similar to the fields of the current Calendar class. CalendarSystem (since the better name Calendar has been taken) encapsulates a mapping between Date and CalendarDate, including methods that manipulate a CalendarDate in calendar-specific ways (say, adding a month).
Taking the current Calendar class, public/protected members could go to the two new classes/interfaces as follows:
CalendarDate: all constants, clear, clone, equals, get, hashCode, set, toString
CalendarSystem: mapToCalendarDate (replaces computeFields, setTime, setTimeInMillis), mapFromCalendarDate (replaces computeTime, getTime, getTimeInMillis), add, clone, equals, getActualMaximum, getActualMinimum, getAvailableLocales, getFirstDayOfWeek, getGreatestMaximum, getGreatestMinimum, getInstance, getLeastMaximum, getMaximum, getMinimalDaysInFirstWeek, getMinimum, getTimeZone (?), hashCode, isLenient, roll, setFirstDayOfWeek, setLenient, setMinimalDaysInFirstWeek, setTimeZone, toString
neither: areFieldsSet, "fields" field, isSet, isTimeSet, time, after, before, complete, computeFields, computeTime, getTime, getTimeInMillis, internalGet, isSet
It might be possible to define CalendarSystem is an interface, and then reimplement Calendar as "extends CalendarDate implements CalendarSystem".
Calendar and GregorianCalendar should be deprecated. All methods referring to them should either be deprecated or be changed to refer to CalendarDate or CalendarSystem.
It's not clear whether a public replacement for GregorianCalendar is needed. Applications should never rely on a specific calendar, but a public class may be useful for pluggable locales.
CR description from 6193609:
I would like to nominate Joda Time (found here: http://joda-time.sourceforge.net/userguide.html) for review by Sun. It seems to provide a rich and extensive replacement for Date and Calendar and replacing those two is certainly well-warranted.
This has been discussed in this discussion forum: http://forums.java.net/jive/thread.jspa?threadID=198&tstart=0
- duplicates
-
JDK-4632590 Make java.util.Calendar.JANUARY = 1
- Closed
-
JDK-4209721 RFE: Calendar is too difficult to subclass
- Closed
-
JDK-4219675 RFE: Calendar is too complicated
- Closed
-
JDK-6193609 (cal) Replace Date/Calendar with Joda Time
- Closed
- relates to
-
JDK-4312621 (cal) API: DST transition handling is ambiguous in GregorianCalendar
- Open
-
JDK-5073554 java.util.Date is a performance bottleneck
- Closed
-
JDK-4609228 (cal) RFE: Provide additional local calendars in Java
- Resolved
-
JDK-6176809 (cal) Create an immutable date type
- Closed