Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Simple tasks:
Browse files Browse the repository at this point in the history
- LocalDate constants for MIN_DATE/MAX_DATE
- LocalTime constants for MIN_TIME/MAX_TIME
- LocalDateTime constants for MIN_DATE_TIME/MAX_DATE_TIME
  • Loading branch information
jespersm committed Jul 6, 2011
1 parent 06bbc2d commit fb52f60
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 11 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.txt
Expand Up @@ -38,6 +38,9 @@
- OffsetTime.compareTo fixed
- OffsetDateTime.compareTo doesn't handle nanos
- Add OffsetDate.atTime(OffsetTime)
- LocalDate constants for MIN_DATE/MAX_DATE (using Year.MIN_VALUE Jan 1/MAX_VALUE Dec 31)
- LocalTime constants for MIN_TIME/MAX_TIME (using MIN = MIDNIGHT, and MAX = 23:59:59.999999999)
- LocalDateTime constants for MIN_DATE_TIME/MAX_DATE_TIME (combining min and max from LocalDate/LocalTime)
- Year.parse(String), Year.parse(String,DateTimeFormatter) and toString(DateTimeFormatter)
- Ensure date-time plus/minus uses long not int
- Fix Period.of(Duration)
Expand Down
3 changes: 0 additions & 3 deletions TODO.txt
Expand Up @@ -32,9 +32,6 @@

Simple tasks
------------
- LocalDate constants for MIN_DATE/MAX_DATE (using Year.MIN_VALUE Jan 1/MAX_VALUE Dec 31)
- LocalTime constants for MIN_TIME/MAX_TIME (using MIN = MIDNIGHT, and MAX = 23:59:59.999999999)
- LocalDateTime constants for MIN_DATE_TIME/MAX_DATE_TIME (combining min and max from LocalDate/LocalTime)
- Obtain rules from TZDB rather than a file


Expand Down
9 changes: 9 additions & 0 deletions src/main/java/javax/time/calendar/LocalDate.java
Expand Up @@ -78,6 +78,15 @@ public final class LocalDate
*/
private static final long serialVersionUID = 1L;

/**
* Constant for the minimum date on the proleptic ISO calendar system, January 1st in -999,999,999.
*/
public static final LocalDate MIN_DATE = LocalDate.of(Year.MIN_YEAR, 1, 1);
/**
* Constant for the maximum date on the proleptic ISO calendar system, December 31st in 999,999,999.
*/
public static final LocalDate MAX_DATE = LocalDate.of(Year.MAX_YEAR, 12, 31);

/**
* The year.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/javax/time/calendar/LocalDateTime.java
Expand Up @@ -63,6 +63,15 @@ public final class LocalDateTime
implements Calendrical, DateTimeProvider, Comparable<LocalDateTime>,
CalendricalMatcher, DateAdjuster, TimeAdjuster, Serializable {

/**
* Constant for the local date and time of midnight of the minimum date.
*/
public static final LocalDateTime MIN_DATE_TIME = LocalDateTime.of(LocalDate.MIN_DATE, LocalTime.MIN_TIME);
/**
* Constant for the local date and time just before midnight, 23:59:59.999999999 in the maximum date.
*/
public static final LocalDateTime MAX_DATE_TIME = LocalDateTime.of(LocalDate.MAX_DATE, LocalTime.MAX_TIME);

/**
* A serialization identifier for this class.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/javax/time/calendar/LocalTime.java
Expand Up @@ -67,6 +67,14 @@
public final class LocalTime
implements Calendrical, TimeProvider, CalendricalMatcher, TimeAdjuster, Comparable<LocalTime>, Serializable {

/**
* Constant for the local time of midnight, 00:00.
*/
public static final LocalTime MIN_TIME;
/**
* Constant for the local time just before midnight, 23:59:59.999999999.
*/
public static final LocalTime MAX_TIME;
/**
* Constant for the local time of midnight, 00:00.
*/
Expand All @@ -85,6 +93,8 @@ public final class LocalTime
}
MIDNIGHT = HOURS[0];
MIDDAY = HOURS[12];
MIN_TIME = HOURS[0];
MAX_TIME = new LocalTime(23, 59, 59, 999999999);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/test/java/javax/time/calendar/TestLocalDate.java
Expand Up @@ -101,8 +101,8 @@ public class TestLocalDate extends AbstractTest {
public void setUp() {
TEST_2007_07_15 = LocalDate.of(2007, 7, 15);

LocalDate max = LocalDate.of(Year.MAX_YEAR, 12, 31);
LocalDate min = LocalDate.of(Year.MIN_YEAR, 1, 1);
LocalDate max = LocalDate.MAX_DATE;
LocalDate min = LocalDate.MIN_DATE;
MAX_VALID_EPOCHDAYS = max.toEpochDay();
MIN_VALID_EPOCHDAYS = min.toEpochDay();
MAX_VALID_MJDAYS = max.toModifiedJulianDay();
Expand Down Expand Up @@ -140,8 +140,12 @@ public void test_immutable() {
assertTrue(Modifier.isFinal(cls.getModifiers()));
Field[] fields = cls.getDeclaredFields();
for (Field field : fields) {
assertTrue(Modifier.isPrivate(field.getModifiers()));
assertTrue(Modifier.isFinal(field.getModifiers()));
if (Modifier.isStatic(field.getModifiers())) {
assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName());
} else {
assertTrue(Modifier.isPrivate(field.getModifiers()), "Field:" + field.getName());
assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName());
}
}
}

Expand All @@ -152,6 +156,15 @@ private void check(LocalDate test_2008_02_29, int y, int m, int d) {
assertEquals(test_2008_02_29.getDayOfMonth(), d);
}

//-----------------------------------------------------------------------
public void constant_MIN_DATE_TIME() {
check(LocalDate.MIN_DATE, Year.MIN_YEAR, 1, 1);
}

public void constant_MAX_DATE_TIME() {
check(LocalDate.MAX_DATE, Year.MAX_YEAR, 12, 31);
}

//-----------------------------------------------------------------------
// now()
//-----------------------------------------------------------------------
Expand Down
21 changes: 17 additions & 4 deletions src/test/java/javax/time/calendar/TestLocalDateTime.java
Expand Up @@ -95,8 +95,8 @@ public class TestLocalDateTime extends AbstractTest {

@BeforeMethod
public void setUp() {
MAX_DATE_TIME = LocalDateTime.of(Year.MAX_YEAR, 12, 31, 0, 0);
MIN_DATE_TIME = LocalDateTime.of(Year.MIN_YEAR, 1, 1, 0, 0);
MAX_DATE_TIME = LocalDateTime.MAX_DATE_TIME;
MIN_DATE_TIME = LocalDateTime.MIN_DATE_TIME;
MAX_INSTANT = MAX_DATE_TIME.atOffset(ZoneOffset.UTC).toInstant();
MIN_INSTANT = MIN_DATE_TIME.atOffset(ZoneOffset.UTC).toInstant();
}
Expand Down Expand Up @@ -140,11 +140,24 @@ public void test_immutable() {
assertTrue(Modifier.isFinal(cls.getModifiers()));
Field[] fields = cls.getDeclaredFields();
for (Field field : fields) {
assertTrue(Modifier.isPrivate(field.getModifiers()));
assertTrue(Modifier.isFinal(field.getModifiers()));
if (Modifier.isStatic(field.getModifiers())) {
assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName());
} else {
assertTrue(Modifier.isPrivate(field.getModifiers()), "Field:" + field.getName());
assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName());
}
}
}

//-----------------------------------------------------------------------
public void constant_MIN_DATE_TIME() {
check(LocalDateTime.MIN_DATE_TIME, Year.MIN_YEAR, 1, 1, 0, 0, 0, 0);
}

public void constant_MAX_DATE_TIME() {
check(LocalDateTime.MAX_DATE_TIME, Year.MAX_YEAR, 12, 31, 23, 59, 59, 999999999);
}

//-----------------------------------------------------------------------
// now()
//-----------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/javax/time/calendar/TestLocalTime.java
Expand Up @@ -151,6 +151,18 @@ public void constant_MIDDAY() {
assertSame(LocalTime.MIDDAY, LocalTime.of(12, 0));
}

//-----------------------------------------------------------------------
public void constant_MIN_TIME() {
check(LocalTime.MIN_TIME, 0, 0, 0, 0);
assertSame(LocalTime.MIN_TIME, LocalTime.of(0, 0));
}

public void constant_MAX_TIME() {
check(LocalTime.MAX_TIME, 23, 59, 59, 999999999);
assertSame(LocalTime.MIDDAY, LocalTime.MIDDAY);
assertSame(LocalTime.MIDDAY, LocalTime.of(12, 0));
}

//-----------------------------------------------------------------------
// now()
//-----------------------------------------------------------------------
Expand Down

0 comments on commit fb52f60

Please sign in to comment.