java.time
The Joda-Time project is now in maintenance mode. The team advises switching to the java.time classes.
Min / max in java.time, see my answer to a similar question.
Joda time
Joda-Time tracks time in milliseconds since the first moment of 1970 in UTC . This counter is maintained using a 64-bit long integer. Thus, technically, the maximum and minimum are the +/- limits of long .
β¦ new DateTime( Long.MIN_VALUE ) β¦ new DateTime( Long.MAX_VALUE )
Joda-Time does not have such minimum / maximum values ββthat could be used as constants. In contrast, note that the Joda-Times successor, java.time, built into Java 8 and later, does offer the constants LocalDateTime.MIN and LocalDateTime.MAX .
By the way, the Joda-Time team advised us to switch to java.time. Most of the java.time functionality is ported to Java 6 and 7 in ThreeTen-Backport , and then adapted for Android in ThreeTen-ABP .
Too big, too small
Beware of these extremes. Their use is not practical. Different libraries, applications, databases, and other receivers / sources of date and time values ββcan have very different restrictions, some much more, but usually much less.
For example, many systems use the old UNIX & POSIX time-tracking tradition as a 32-bit integer for integer seconds from 1970-01-01T00: 00: 00Z. A natural +/- limit of two billion seconds leads to an impending 2038 problem .
Another limitation is the physical size of the display of fields in forms and reports that expect only four digits in the year number.
Temporary solution
You can define your own minimum / maximum.
You may need extreme values ββsuch as year 0000 and year 9999. Joda-Time supports years later than 9.999, but I would stick with 4 digits to fit the commonly used formats for displaying on the screen and in reports. Visually, four nines stand out as a dummy date.
Or you may need the expected minimum value that matches your business logic. If you are creating a new billing system, then you know that a year should always be this year or later.
I suggest defining constants on a helper class. Something like that:
package com.example; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; public class JodaTimeHelper { static final public DateTime START_OF_TIME = new DateTime( 0000, 1, 1, 0, 0, 0, DateTimeZone.UTC ); static final public DateTime END_OF_TIME = new DateTime( 9999, 1, 1, 0, 0, 0, DateTimeZone.UTC ); static final public DateTime MINIMUM_INVOICE_DATETIME = new DateTime( 2015, 1, 1, 0, 0, 0, DateTimeZone.UTC ); }
Here is the syntax for invoking these constants.
System.out.println( "START_OF_TIME: " + JodaTimeHelper.START_OF_TIME ); System.out.println( "END_OF_TIME: " + JodaTimeHelper.END_OF_TIME ); System.out.println( "MINIMUM_INVOICE_DATETIME: " + JodaTimeHelper. MINIMUM_INVOICE_DATETIME );
When run.
START_OF_TIME: 0000-01-01T00:00:00.000Z END_OF_TIME: 9999-01-01T00:00:00.000Z MINIMUM_INVOICE_DATETIME: 2015-01-01T00:00:00.000Z