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

Commit

Permalink
Remove week-of-month and week-of-year
Browse files Browse the repository at this point in the history
These will be handled separately in WeekDefinition
See #67
  • Loading branch information
jodastephen committed Dec 4, 2012
1 parent 84024a8 commit 280f25a
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 116 deletions.
14 changes: 0 additions & 14 deletions src/main/java/javax/time/LocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,6 @@ private LocalDate(int year, int month, int dayOfMonth) {
}

//-----------------------------------------------------------------------
@Override
public boolean isSupported(DateTimeField field) {
if (field instanceof ChronoField) {
return ((ChronoField) field).isDateField();
}
return field != null && field.doIsSupported(this);
}

@Override
public DateTimeValueRange range(DateTimeField field) {
if (field instanceof ChronoField) {
Expand All @@ -442,8 +434,6 @@ public DateTimeValueRange range(DateTimeField field) {
case DAY_OF_MONTH: return DateTimeValueRange.of(1, lengthOfMonth());
case DAY_OF_YEAR: return DateTimeValueRange.of(1, lengthOfYear());
case ALIGNED_WEEK_OF_MONTH: return DateTimeValueRange.of(1, getMonth() == Month.FEBRUARY && isLeapYear() == false ? 4 : 5);
case WEEK_OF_MONTH: throw new UnsupportedOperationException("TODO");
case WEEK_OF_YEAR: throw new UnsupportedOperationException("TODO");
case YEAR_OF_ERA:
return (getYear() <= 0 ? DateTimeValueRange.of(1, MAX_YEAR + 1) : DateTimeValueRange.of(1, MAX_YEAR));
}
Expand Down Expand Up @@ -485,9 +475,7 @@ private int get0(DateTimeField field) {
case DAY_OF_YEAR: return getDayOfYear();
case EPOCH_DAY: throw new DateTimeException("Field too large for an int: " + field);
case ALIGNED_WEEK_OF_MONTH: return ((day - 1) / 7) + 1;
case WEEK_OF_MONTH: throw new UnsupportedOperationException("TODO");
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case WEEK_OF_YEAR: throw new UnsupportedOperationException("TODO");
case MONTH_OF_YEAR: return month;
case EPOCH_MONTH: throw new DateTimeException("Field too large for an int: " + field);
case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
Expand Down Expand Up @@ -746,9 +734,7 @@ public LocalDate with(DateTimeField field, long newValue) {
case DAY_OF_YEAR: return withDayOfYear((int) newValue);
case EPOCH_DAY: return LocalDate.ofEpochDay(newValue);
case ALIGNED_WEEK_OF_MONTH: return plusWeeks(newValue - getLong(ALIGNED_WEEK_OF_MONTH));
case WEEK_OF_MONTH: throw new UnsupportedOperationException("TODO");
case ALIGNED_WEEK_OF_YEAR: return plusWeeks(newValue - getLong(ALIGNED_WEEK_OF_YEAR));
case WEEK_OF_YEAR: throw new UnsupportedOperationException("TODO");
case MONTH_OF_YEAR: return withMonth((int) newValue);
case EPOCH_MONTH: return plusMonths(newValue - getLong(EPOCH_MONTH));
case YEAR_OF_ERA: return withYear((int) (year >= 1 ? newValue : 1 - newValue));
Expand Down
46 changes: 0 additions & 46 deletions src/main/java/javax/time/calendrical/ChronoField.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,29 +323,6 @@ public enum ChronoField implements DateTimeField {
* field in the same way, but using the alternate week length.
*/
ALIGNED_WEEK_OF_MONTH("AlignedWeekOfMonth", WEEKS, MONTHS, DateTimeValueRange.of(1, 4, 5)),
/**
* The week within a month.
* <p>
* This represents concept of the count of weeks within the month where weeks
* start on a fixed day-of-week, such as Monday.
* This field is typically used with {@link #DAY_OF_WEEK}.
* <p>
* In the default ISO calendar system, the week starts on Monday and there must be at
* least 4 days in the first week.
* Week one is the week starting on a Monday where there are at least 4 days in the month.
* Thus, week one may start up to three days before the start of the month.
* If the first week starts after the start of the month then the period before is week zero.
* <p>
* For example:<br />
* - if the 1st day of the month is a Monday, week one starts on the 1st and there is no week zero<br />
* - if the 2nd day of the month is a Monday, week one starts on the 2nd and the 1st is in week zero<br />
* - if the 4th day of the month is a Monday, week one starts on the 4th and the 1st to 3rd is in week zero<br />
* - if the 5th day of the month is a Monday, week two starts on the 5th and the 1st to 4th is in week one<br />
* <p>
* Non-ISO calendar systems should implement this field in the same way, taking
* into account any differences in week or month length.
*/
WEEK_OF_MONTH("WeekOfMonth", WEEKS, MONTHS, DateTimeValueRange.of(0, 1, 4, 5)),
/**
* The aligned week within a year.
* <p>
Expand All @@ -362,29 +339,6 @@ public enum ChronoField implements DateTimeField {
* field in the same way, but using the alternate week length.
*/
ALIGNED_WEEK_OF_YEAR("AlignedWeekOfYear", WEEKS, YEARS, DateTimeValueRange.of(1, 53)),
/**
* The week within a year.
* <p>
* This represents concept of the count of weeks within the year where weeks
* start on a fixed day-of-week, such as Monday.
* This field is typically used with {@link #DAY_OF_WEEK}.
* <p>
* In the default ISO calendar system, the week starts on Monday and there must be at
* least 4 days in the first week.
* Week one is the week starting on a Monday where there are at least 4 days in the year.
* Thus, week one may start up to three days before the start of the year.
* If the first week starts after the start of the year then the period before is week zero.
* <p>
* For example:<br />
* - if the 1st day of the year is a Monday, week one starts on the 1st and there is no week zero<br />
* - if the 2nd day of the year is a Monday, week one starts on the 2nd and the 1st is in week zero<br />
* - if the 4th day of the year is a Monday, week one starts on the 4th and the 1st to 3rd is in week zero<br />
* - if the 5th day of the year is a Monday, week two starts on the 5th and the 1st to 4th is in week one<br />
* <p>
* Non-ISO calendar systems should implement this field in the same way, taking
* into account any differences in week or year length.
*/
WEEK_OF_YEAR("WeekOfYear", WEEKS, YEARS, DateTimeValueRange.of(0, 1, 52, 53)),
/**
* The month-of-year, such as March.
* <p>
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/javax/time/chrono/global/ChronoDateImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,14 @@
*/
package javax.time.chrono.global;

import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;

import java.io.Serializable;

import javax.time.DateTimeException;
import javax.time.LocalDate;
import javax.time.LocalTime;
import javax.time.calendrical.ChronoField;
import javax.time.calendrical.ChronoUnit;
import javax.time.calendrical.DateTime;
import javax.time.calendrical.DateTime.WithAdjuster;
import javax.time.calendrical.DateTimeField;
import javax.time.calendrical.PeriodUnit;
import javax.time.chrono.Chrono;
import javax.time.chrono.ChronoLocalDate;
Expand Down Expand Up @@ -132,16 +127,6 @@ abstract class ChronoDateImpl<C extends Chrono<C>>
ChronoDateImpl() {
}

//-----------------------------------------------------------------------
@Override
public boolean isSupported(DateTimeField field) {
if (field instanceof ChronoField) {
return ((ChronoField) field).isDateField() &&
field != WEEK_OF_MONTH && field != WEEK_OF_YEAR;
}
return field != null && field.doIsSupported(this);
}

//-----------------------------------------------------------------------
@Override
public ChronoDateImpl<C> plus(long amountToAdd, PeriodUnit unit) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/javax/time/chrono/global/JapaneseChrono.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,6 @@ public DateTimeValueRange range(ChronoField field) {
case MONTH_OF_YEAR:
return DateTimeValueRange.of(jcal.getMinimum(Calendar.MONTH) + 1, jcal.getGreatestMinimum(Calendar.MONTH) + 1,
jcal.getLeastMaximum(Calendar.MONTH) + 1, jcal.getMaximum(Calendar.MONTH) + 1);
case WEEK_OF_YEAR:
// TODO: revisit this when the week definition gets clear
fieldIndex = Calendar.WEEK_OF_YEAR;
break;
case DAY_OF_YEAR:
fieldIndex = Calendar.DAY_OF_YEAR;
break;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/javax/time/chrono/global/JapaneseDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ public long getLong(DateTimeField field) {
LocalGregorianCalendar.Date jdate = toPrivateJapaneseDate(isoDate);
return JapaneseChrono.JCAL.getDayOfYear(jdate);
}
case WEEK_OF_YEAR:
// TODO: need to resolve week of year issues with Japanese calendar.
break;
}
// TODO: review other fields
return isoDate.getLong(field);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/javax/time/jdk8/DefaultInterfaceChronoLocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import java.util.Objects;

import javax.time.LocalTime;
import javax.time.calendrical.ChronoField;
import javax.time.calendrical.DateTime;
import javax.time.calendrical.DateTimeField;
import javax.time.calendrical.PeriodUnit;
import javax.time.chrono.Chrono;
import javax.time.chrono.ChronoLocalDate;
Expand Down Expand Up @@ -74,6 +76,14 @@ public int lengthOfYear() {
return (isLeapYear() ? 366 : 365);
}

@Override
public boolean isSupported(DateTimeField field) {
if (field instanceof ChronoField) {
return ((ChronoField) field).isDateField();
}
return field != null && field.doIsSupported(this);
}

//-------------------------------------------------------------------------
@Override
public ChronoLocalDate<C> with(WithAdjuster adjuster) {
Expand Down
4 changes: 0 additions & 4 deletions src/tck/java/javax/time/TCKLocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import static javax.time.calendrical.ChronoField.EPOCH_MONTH;
import static javax.time.calendrical.ChronoField.ERA;
import static javax.time.calendrical.ChronoField.MONTH_OF_YEAR;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -131,9 +129,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
4 changes: 0 additions & 4 deletions src/tck/java/javax/time/TCKLocalDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import static javax.time.calendrical.ChronoField.NANO_OF_SECOND;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static javax.time.calendrical.ChronoUnit.NANOS;
Expand Down Expand Up @@ -157,9 +155,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
6 changes: 1 addition & 5 deletions src/tck/java/javax/time/TCKOffsetDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import static javax.time.calendrical.ChronoField.ERA;
import static javax.time.calendrical.ChronoField.MONTH_OF_YEAR;
import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
Expand All @@ -64,8 +62,8 @@
import javax.time.calendrical.DateTime.MinusAdjuster;
import javax.time.calendrical.DateTime.PlusAdjuster;
import javax.time.calendrical.DateTime.WithAdjuster;
import javax.time.calendrical.DateTimeAccessor.Query;
import javax.time.calendrical.DateTimeAccessor;
import javax.time.calendrical.DateTimeAccessor.Query;
import javax.time.calendrical.DateTimeField;
import javax.time.calendrical.JulianDayField;
import javax.time.calendrical.MockFieldNoValue;
Expand Down Expand Up @@ -110,9 +108,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
6 changes: 1 addition & 5 deletions src/tck/java/javax/time/TCKOffsetDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static javax.time.calendrical.ChronoUnit.NANOS;
Expand All @@ -79,8 +77,8 @@
import javax.time.calendrical.ChronoUnit;
import javax.time.calendrical.DateTime;
import javax.time.calendrical.DateTime.WithAdjuster;
import javax.time.calendrical.DateTimeAccessor.Query;
import javax.time.calendrical.DateTimeAccessor;
import javax.time.calendrical.DateTimeAccessor.Query;
import javax.time.calendrical.DateTimeField;
import javax.time.calendrical.JulianDayField;
import javax.time.calendrical.MockFieldNoValue;
Expand Down Expand Up @@ -144,9 +142,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
4 changes: 0 additions & 4 deletions src/tck/java/javax/time/TCKZonedDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static javax.time.calendrical.ChronoUnit.DAYS;
Expand Down Expand Up @@ -162,9 +160,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/javax/time/TestLocalDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import static javax.time.calendrical.ChronoField.EPOCH_MONTH;
import static javax.time.calendrical.ChronoField.ERA;
import static javax.time.calendrical.ChronoField.MONTH_OF_YEAR;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -96,9 +94,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/javax/time/TestLocalDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import static javax.time.calendrical.ChronoField.NANO_OF_SECOND;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -120,9 +118,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/javax/time/TestOffsetDateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
import static javax.time.calendrical.ChronoField.YEAR;
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertSame;
Expand Down Expand Up @@ -128,9 +126,7 @@ protected List<DateTimeField> validFields() {
DAY_OF_YEAR,
EPOCH_DAY,
ALIGNED_WEEK_OF_MONTH,
WEEK_OF_MONTH,
ALIGNED_WEEK_OF_YEAR,
WEEK_OF_YEAR,
MONTH_OF_YEAR,
EPOCH_MONTH,
YEAR_OF_ERA,
Expand Down

0 comments on commit 280f25a

Please sign in to comment.