A partial in Joda-Time is a partial date and time representation. All implementations represent local dates and times, and do not reference a time zone. As such, they only partially represent a date or time in the datetime continuum.
The main implementations changed in version 1.3. This was to address implementation issues with the original design. The previous classes - TimeofDay and YearMonthDay - are now effectively deprecated. The new implementations are LocalDate, LocalTime and LocalDateTime.
It is not possible to directly interoperate between a partial and an instant. A partial does not fully specify a single point in the datetime continuum, but instead may match multiple points. For example, a LocalTime occurs one per day on the datetime continuum.
A partial can be converted to a full instant by specifying the missing values. At a minimum the time zone must be specified. It may be necessary to specify other missing fields. For example, to convert a LocalDate to a DateTime requires filling in the time fields and the time zone.
In terms of datetime maths, you could write:
partial + missing fields + time zone = instant
Two classes represent a date in Joda-Time - DateMidnight and LocalDate. These have different meanings. DateMidnight is a fully specified instant, with a time zone. It is defined as the milliseond instant at exactly mignight (00:00) at the start of a day. LocalDate defines a day using the year, monthOfYear and dayOfMonth fields and no time zone. It can be thought of as a local date that covers the whole of the day from 00:00 to 23:59.
Within Joda-Time a partial is represented by the ReadablePartial interface. There are six implementations of the interface provided:
The code can be used in various ways:
// setup objects LocalDate date = new LocalDate(2004, 12, 25); LocalTime time = new LocalTime(12, 20); int year = date.getYear(); // returns 2004 int hour = time.getHour(); // returns 12 String monthStr = date.month().getAsText(); // returns 'December'
LocalDate date = new LocalDate(2004, 12, 25); LocalTime time = new LocalTime(12, 20); // merge, resulting in 2004-25-12T12:20 (default time zone) DateTime dt = date.toDateTime(time); // extract the date fields from someDT DateTime someDT = ... LocalDate date = new LocalDate(someDT);
Note that the interface ReadablePartial should not be used like the collections API. The interface only contains the core subset of the operations. Instead, you should refer directly to the implementation classes in your APIs.