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

Commit

Permalink
Remove DateAdjuster/TimeAdjuster from Offset* classes
Browse files Browse the repository at this point in the history
These interfaces caused problems in some API signatures, such as ODT.with(OD) only setting the LD. The with() methods have been fixed up and clarified to handle the change
  • Loading branch information
jodastephen committed Sep 30, 2011
1 parent 506c744 commit c4a1ee5
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 271 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Expand Up @@ -99,6 +99,7 @@
- Remove LocalTime.Overflow, embedding code in LocalDateTime
- Rename DateTimeFormatter methods for clarity
- Move TimeDefinition to rule class from builder
- Remove DateAdjuster/TimeAdjuster from Offset* classes and clarify with methods

0.6.3
===============================================================================
Expand Down
13 changes: 8 additions & 5 deletions TODO.txt
Expand Up @@ -53,14 +53,16 @@ Time scales (UTC/TAI)
Date/Time classes
- DateResolver rework - takes int or MonthOfDay or calendricals
- OffsetDateTime.toEpochSecs() could be private
- with(Calendrical) - need to figure out how
- remove ISO chronology from LocalDate etc classes
? InstantProvider implementations toEpochMillis()
? getMonthOfYear() -> getMonth(), etc
? with(rule, value)
? Calendrical rule for date/time as a period (for between calculations)
? MonthOfYear methods taking year, as well as boolean

Rules
- DateTimeField.from(Cal...)
- Change DAY_OF_MONTH.field(6) to DAY_OF_MONTH.of(6) - to act like factories, also period units
- ensure other calendar systems re-use ISO defined rules
- Handle case where values have gaps, eg 1,2, 4,5,6, 8
? parse()
Expand All @@ -85,9 +87,9 @@ Date/Time formatting
Time zones
- Use WET/CET/EET as valid short abbreviations?
- SPI for zone names
# some zones have transitions where only the name changes - America/Resolute
# "resolvers need to use correct rules" what does this mean?
- parse/format names
# some zones have transitions where only the name changes - America/Resolute
- aliases resolved at runtime not compile time
- test against TZDB binary data
? get region ids by offset (JDK method)
? Drop Etc (signs reversed), Older country based IDs
Expand All @@ -104,12 +106,11 @@ Time zones

Periods
- WIP branch, decide on normalization
- Between factories
- Between factories -> ? DAYS.between(date1, date2)
- Formatting/parsing (defer?)
- Period.toString is not output of state

Matchers/Adjusters
- DateTimeAdjuster
- more general next/previous
? recurrences

Expand Down Expand Up @@ -191,3 +192,5 @@ Not doing
- Rename DateProvider to LocalDateProvider - NO, interface was removed
- Rename period classes - NO, current names seem fine
- Promote TimeDefinition to top-level type - NO, moved it to rule class instead
- date.with(RULE, value) / date.plus(amount, UNIT) - NO, because date.plus(UNIT.of(amount)) works well enough
- DateTimeAdjuster - NO, it adds more complexity
40 changes: 5 additions & 35 deletions src/main/java/javax/time/calendar/OffsetDate.java
Expand Up @@ -59,7 +59,7 @@
* @author Stephen Colebourne
*/
public final class OffsetDate
implements Calendrical, CalendricalMatcher, DateAdjuster, Comparable<OffsetDate>, Serializable {
implements Calendrical, CalendricalMatcher, Comparable<OffsetDate>, Serializable {

/**
* Serialization version.
Expand Down Expand Up @@ -440,37 +440,20 @@ public boolean isLeapYear() {
/**
* Returns a copy of this {@code OffsetDate} with the date altered using the adjuster.
* <p>
* Adjusters can be used to alter the date in various ways.
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* <p>
* The offset does not affect the calculation and will be the same in the result.
* This adjusts the date according to the rules of the specified adjuster.
* The offset is not part of the calculation and will be unchanged in the result.
* Note that {@link LocalDate} implements {@code DateAdjuster}, thus this method
* can be used to change the entire date.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetDate} based on this date adjusted as necessary, not null
* @throws NullPointerException if the adjuster returned null
*/
public OffsetDate with(DateAdjuster adjuster) {
return with(date.with(adjuster), offset);
}

//-----------------------------------------------------------------------
/**
* Returns a copy of this {@code OffsetDate} with a different local date.
* <p>
* This method changes the date stored to a different date.
* No calculation is performed. The result simply represents the same
* offset and the new date.
*
* @param date the local date to change to, not null
* @return an {@code OffsetDate} based on this date with the requested date, not null
*/
public OffsetDate withDate(LocalDate date) {
return this.date.equals(date) ? this : new OffsetDate(date, offset);
}

//-----------------------------------------------------------------------
/**
* Returns a copy of this {@code OffsetDate} with the year altered.
Expand Down Expand Up @@ -965,19 +948,6 @@ public boolean matchesCalendrical(Calendrical calendrical) {
return this.equals(calendrical.get(rule()));
}

/**
* Adjusts a date to have the value of the date part of this object.
* <p>
* This method implements the {@code DateAdjuster} interface.
* It is intended that applications use {@link #with(DateAdjuster)} rather than this method.
*
* @param date the date to be adjusted, not null
* @return the adjusted date, not null
*/
public LocalDate adjustDate(LocalDate date) {
return this.date.adjustDate(date);
}

//-----------------------------------------------------------------------
/**
* Returns an offset date-time formed from this date at the specified time.
Expand Down
55 changes: 12 additions & 43 deletions src/main/java/javax/time/calendar/OffsetDateTime.java
Expand Up @@ -59,8 +59,7 @@
*/
public final class OffsetDateTime
implements InstantProvider, Calendrical,
CalendricalMatcher, DateAdjuster, TimeAdjuster,
Comparable<OffsetDateTime>, Serializable {
CalendricalMatcher, Comparable<OffsetDateTime>, Serializable {

/**
* Serialization version.
Expand Down Expand Up @@ -744,45 +743,41 @@ public boolean isLeapYear() {
* No calculation is needed or performed.
*
* @param dateTime the local date-time to change to, not null
* @return an {@code OffsetDateTime} based on this time with the requested time, not null
* @return an {@code OffsetDateTime} based on this time with the requested date-time, not null
*/
public OffsetDateTime withDateTime(LocalDateTime dateTime) {
return this.dateTime.equals(dateTime) ? this : new OffsetDateTime(dateTime, offset);
}

/**
* Returns a copy of this OffsetDateTime with the date altered using the adjuster.
* Returns a copy of this {@code OffsetDateTime} with the date altered using the adjuster.
* <p>
* Adjusters can be used to alter the date in various ways.
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the date to the last day of the month.
* <p>
* The offset and time do not affect the calculation and will be the same in the result.
* This adjusts the date according to the rules of the specified adjuster.
* The time and offset are not part of the calculation and will be unchanged in the result.
* Note that {@link LocalDate} implements {@code DateAdjuster}, thus this method
* can be used to change the entire date.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetDateTime} based on this date-time with the date adjusted, not null
* @throws NullPointerException if the adjuster returned null
*/
public OffsetDateTime with(DateAdjuster adjuster) {
return with(dateTime.with(adjuster), offset);
}

/**
* Returns a copy of this OffsetDateTime with the time altered using the adjuster.
* <p>
* Adjusters can be used to alter the time in various ways.
* A simple adjuster might simply set the one of the fields, such as the hour field.
* A more complex adjuster might set the time to end of the working day.
* Returns a copy of this {@code OffsetDateTime} with the time altered using the adjuster.
* <p>
* The offset and date do not affect the calculation and will be the same in the result.
* This adjusts the time according to the rules of the specified adjuster.
* The date and offset are not part of the calculation and will be unchanged in the result.
* Note that {@link LocalTime} implements {@code TimeAdjuster}, thus this method
* can be used to change the entire time.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param adjuster the adjuster to use, not null
* @return an {@code OffsetDateTime} based on this date-time with the time adjusted, not null
* @throws IllegalArgumentException if the adjuster returned null
*/
public OffsetDateTime with(TimeAdjuster adjuster) {
return with(dateTime.with(adjuster), offset);
Expand Down Expand Up @@ -1590,32 +1585,6 @@ public boolean matchesCalendrical(Calendrical calendrical) {
return this.equals(calendrical.get(rule()));
}

/**
* Adjusts a date to have the value of the date part of this object.
* <p>
* This method implements the {@code DateAdjuster} interface.
* It is intended that applications use {@link #with(DateAdjuster)} rather than this method.
*
* @param date the date to be adjusted, not null
* @return the adjusted date, not null
*/
public LocalDate adjustDate(LocalDate date) {
return dateTime.adjustDate(date);
}

/**
* Adjusts a time to have the value of the time part of this object.
* <p>
* This method implements the {@code TimeAdjuster} interface.
* It is intended that applications use {@link #with(TimeAdjuster)} rather than this method.
*
* @param time the time to be adjusted, not null
* @return the adjusted time, not null
*/
public LocalTime adjustTime(LocalTime time) {
return dateTime.adjustTime(time);
}

//-----------------------------------------------------------------------
/**
* Returns a zoned date-time formed from the instant represented by this
Expand Down
38 changes: 6 additions & 32 deletions src/main/java/javax/time/calendar/OffsetTime.java
Expand Up @@ -61,7 +61,7 @@
* @author Stephen Colebourne
*/
public final class OffsetTime
implements Calendrical, CalendricalMatcher, TimeAdjuster, Comparable<OffsetTime>, Serializable {
implements Calendrical, CalendricalMatcher, Comparable<OffsetTime>, Serializable {

/**
* Serialization version.
Expand Down Expand Up @@ -325,20 +325,6 @@ public <T> T get(CalendricalRule<T> ruleToDerive) {
return CalendricalEngine.derive(ruleToDerive, rule(), null, time, offset, null, ISOChronology.INSTANCE, null);
}

//-----------------------------------------------------------------------
/**
* Returns a copy of this {@code OffsetTime} with the time altered and the offset retained.
* <p>
* This method returns an object with the same {@code ZoneOffset} and the specified {@code LocalTime}.
* No calculation is needed or performed.
*
* @param time the local time to change to, not null
* @return an {@code OffsetTime} based on this time with the requested time, not null
*/
public OffsetTime withTime(LocalTime time) {
return this.time.equals(time) ? this : new OffsetTime(time, offset);
}

//-----------------------------------------------------------------------
/**
* Gets the zone offset representing how far ahead or behind UTC the time is.
Expand Down Expand Up @@ -438,9 +424,10 @@ public int getNanoOfSecond() {
/**
* Returns a copy of this {@code OffsetTime} with the time altered using the adjuster.
* <p>
* Adjusters can be used to alter the time in various ways.
* A simple adjuster might simply set the one of the fields, such as the hour field.
* A more complex adjuster might set the time to end of the working day.
* This adjusts the time according to the rules of the specified adjuster.
* The offset is not part of the calculation and will be unchanged in the result.
* Note that {@link LocalTime} implements {@code TimeAdjuster}, thus this method
* can be used to change the entire time.
* <p>
* This instance is immutable and unaffected by this method call.
*
Expand All @@ -449,7 +436,7 @@ public int getNanoOfSecond() {
*/
public OffsetTime with(TimeAdjuster adjuster) {
LocalTime newTime = time.with(adjuster);
return newTime == this.time ? this : new OffsetTime(newTime, offset);
return newTime.equals(this.time) ? this : new OffsetTime(newTime, offset);
}

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -752,19 +739,6 @@ public boolean matchesCalendrical(Calendrical calendrical) {
return this.equals(calendrical.get(rule()));
}

/**
* Adjusts a time to have the value of the time part of this object.
* <p>
* This method implements the {@code TimeAdjuster} interface.
* It is intended that applications use {@link #with(TimeAdjuster)} rather than this method.
*
* @param time the time to be adjusted, not null
* @return the adjusted time, not null
*/
public LocalTime adjustTime(LocalTime time) {
return this.time.adjustTime(time);
}

//-----------------------------------------------------------------------
/**
* Converts this time to a {@code LocalTime}.
Expand Down

0 comments on commit c4a1ee5

Please sign in to comment.