Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/main/java/org/threeten/extra/AmPm.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,9 @@ public long getLong(TemporalField field) {
/**
* Queries this am-pm using the specified query.
* <p>
* This queries this am-pm using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#precision()} is directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/org/threeten/extra/DayOfMonth.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
Expand Down Expand Up @@ -366,14 +367,9 @@ public boolean isValidYearMonth(YearMonth yearMonth) {
/**
* Queries this day-of-month using the specified query.
* <p>
* This queries this day-of-month using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand All @@ -386,6 +382,8 @@ public boolean isValidYearMonth(YearMonth yearMonth) {
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.DAYS;
}
return TemporalAccessor.super.query(query);
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/threeten/extra/DayOfYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
Expand Down Expand Up @@ -350,7 +351,7 @@ public long getLong(TemporalField field) {
/**
* Checks if the year is valid for this day-of-year.
* <p>
* This method checks whether this day-of-yearand the input year form
* This method checks whether this day-of-year and the input year form
* a valid date. This can only return false for day-of-year 366.
*
* @param year the year to validate
Expand All @@ -364,14 +365,9 @@ public boolean isValidYear(int year) {
/**
* Queries this day-of-year using the specified query.
* <p>
* This queries this day-of-year using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand All @@ -384,6 +380,8 @@ public boolean isValidYear(int year) {
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.DAYS;
}
return TemporalAccessor.super.query(query);
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/threeten/extra/Half.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public int getValue() {

//-----------------------------------------------------------------------
/**
* Gets the textual representation, such as 'H1' or '4th half'.
* Gets the textual representation, such as 'H1' or '2nd half'.
* <p>
* This returns the textual name used to identify the half-of-year,
* suitable for presentation to the user.
Expand Down Expand Up @@ -362,7 +362,7 @@ public Half minus(long halves) {
* H2 has 184 days.
*
* @param leapYear true if the length is required for a leap year
* @return the length of this month in days, 181, 182 or 184
* @return the length of this half in days, 181, 182 or 184
*/
public int length(boolean leapYear) {
return this == H1 ? (leapYear ? 182 : 181) : 184;
Expand All @@ -385,14 +385,9 @@ public Month firstMonth() {
/**
* Queries this half-of-year using the specified query.
* <p>
* This queries this half-of-year using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
19 changes: 7 additions & 12 deletions src/main/java/org/threeten/extra/HourMinute.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public ValueRange range(TemporalField field) {
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return valid
* values based on this hour-minute,.
* values based on this hour-minute.
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
Expand Down Expand Up @@ -674,13 +674,13 @@ public HourMinute plus(TemporalAmount amountToAdd) {
* The supported fields behave as follows:
* <ul>
* <li>{@code MINUTES} -
* Returns a {@code LocalTime} with the specified number of minutes added.
* Returns an {@code HourMinute} with the specified number of minutes added.
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corrected documentation refers to 'HourMinute' but this appears to be in the wrong method context. This comment should be part of the plus() method documentation, not the query() method documentation.

Copilot uses AI. Check for mistakes.
* This is equivalent to {@link #plusMinutes(long)}.
* <li>{@code HOURS} -
* Returns a {@code LocalTime} with the specified number of hours added.
* Returns an {@code HourMinute} with the specified number of hours added.
* This is equivalent to {@link #plusHours(long)}.
* <li>{@code HALF_DAYS} -
* Returns a {@code LocalTime} with the specified number of half-days added.
* Returns an {@code HourMinute} with the specified number of half-days added.
* This is equivalent to {@link #plusHours(long)} with the amount
* multiplied by 12.
* </ul>
Expand Down Expand Up @@ -842,14 +842,9 @@ public HourMinute minusMinutes(long minutesToSubtract) {
/**
* Queries this hour-minute using the specified query.
* <p>
* This queries this hour-minute using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#localTime()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/threeten/extra/OffsetDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -1050,14 +1050,10 @@ public OffsetDate minusDays(long days) {
/**
* Queries this date using the specified query.
* <p>
* This queries this date using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#localDate()}, {@link TemporalQueries#chronology()}, {@link TemporalQueries#offset()},
* {@link TemporalQueries#zone()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand All @@ -1068,7 +1064,9 @@ public OffsetDate minusDays(long days) {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
if (query == TemporalQueries.localDate()) {
return (R) date;
} else if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) DAYS;
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/threeten/extra/Quarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public Quarter minus(long quarters) {
* Q3 and Q4 have 92 days.
*
* @param leapYear true if the length is required for a leap year
* @return the length of this month in days, from 90 to 92
* @return the length of this quarter in days, from 90 to 92
*/
public int length(boolean leapYear) {
switch (this) {
Expand Down Expand Up @@ -429,14 +429,9 @@ public Month firstMonth() {
/**
* Queries this quarter-of-year using the specified query.
* <p>
* This queries this quarter-of-year using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/threeten/extra/YearHalf.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static YearHalf from(TemporalAccessor temporal) {
* Obtains an instance of {@code YearHalf} from a text string such as {@code 2007-H2}.
* <p>
* The string must represent a valid year-half.
* The format must be {@code uuuu-'Q'Q} where the 'Q' is case insensitive.
* The format must be {@code uuuu-'H'H} where the 'H' is case insensitive.
* Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
*
* @param text the text to parse such as "2007-H2", not null
Expand Down Expand Up @@ -452,7 +452,7 @@ public ValueRange range(TemporalField field) {
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return valid
* values based on this year-half,.
* values based on this year-half.
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
Expand Down Expand Up @@ -974,14 +974,9 @@ public YearHalf minusHalves(long halvesToSubtract) {
/**
* Queries this year-half using the specified query.
* <p>
* This queries this year-half using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
13 changes: 4 additions & 9 deletions src/main/java/org/threeten/extra/YearQuarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public ValueRange range(TemporalField field) {
* <p>
* If the field is a {@link ChronoField} then the query is implemented here.
* The {@link #isSupported(TemporalField) supported fields} will return valid
* values based on this year-quarter,.
* values based on this year-quarter.
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
* <p>
* If the field is not a {@code ChronoField}, then the result of this method
Expand Down Expand Up @@ -975,14 +975,9 @@ public YearQuarter minusQuarters(long quartersToSubtract) {
/**
* Queries this year-quarter using the specified query.
* <p>
* This queries this year-quarter using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/org/threeten/extra/YearWeek.java
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,9 @@ public YearWeek minusWeeks(long weeksToSubtract) {
/**
* Queries this year-week using the specified query.
* <p>
* This queries this year-week using the specified query strategy object.
* The {@code TemporalQuery} object defines the logic to be used to
* obtain the result. Read the documentation of the query to understand
* what the result of this method will be.
* <p>
* The result of this method is obtained by invoking the
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
* specified query passing {@code this} as the argument.
* {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported.
* Otherwise, the result of this method is obtained by invoking
* {@link TemporalAccessor#query(TemporalQuery)} on the parent interface.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
Expand All @@ -862,6 +857,8 @@ public YearWeek minusWeeks(long weeksToSubtract) {
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) WEEKS;
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant WEEKS is not defined in this class or imported. This should be ChronoUnit.WEEKS to match the pattern used in other classes like DayOfMonth and DayOfYear.

Suggested change
return (R) WEEKS;
return (R) ChronoUnit.WEEKS;

Copilot uses AI. Check for mistakes.
}
return Temporal.super.query(query);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/threeten/extra/TestDayOfMonth.java
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public void test_query() {
assertEquals(null, TEST.query(TemporalQueries.localDate()));
assertEquals(null, TEST.query(TemporalQueries.localTime()));
assertEquals(null, TEST.query(TemporalQueries.offset()));
assertEquals(null, TEST.query(TemporalQueries.precision()));
assertEquals(ChronoUnit.DAYS, TEST.query(TemporalQueries.precision()));
assertEquals(null, TEST.query(TemporalQueries.zone()));
assertEquals(null, TEST.query(TemporalQueries.zoneId()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/threeten/extra/TestDayOfYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public void test_query() {
assertEquals(null, TEST.query(TemporalQueries.localDate()));
assertEquals(null, TEST.query(TemporalQueries.localTime()));
assertEquals(null, TEST.query(TemporalQueries.offset()));
assertEquals(null, TEST.query(TemporalQueries.precision()));
assertEquals(ChronoUnit.DAYS, TEST.query(TemporalQueries.precision()));
assertEquals(null, TEST.query(TemporalQueries.zone()));
assertEquals(null, TEST.query(TemporalQueries.zoneId()));
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/threeten/extra/TestOffsetDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,18 @@ public void test_query_zone() {
assertEquals(OFFSET_PONE, TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE));
}

@Test
public void test_query_localDate() {
assertEquals(TEST_2007_07_15_PONE.toLocalDate(), TEST_2007_07_15_PONE.query(TemporalQueries.localDate()));
assertEquals(TEST_2007_07_15_PONE.toLocalDate(), TemporalQueries.localDate().queryFrom(TEST_2007_07_15_PONE));
}

@Test
public void test_query_localTime() {
assertNull(TEST_2007_07_15_PONE.query(TemporalQueries.localTime()));
assertNull(TemporalQueries.localTime().queryFrom(TEST_2007_07_15_PONE));
}

@Test
public void test_query_null() {
assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.query(null));
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/threeten/extra/TestYearWeek.java
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ public void test_query() {
assertEquals(null, TEST.query(TemporalQueries.localDate()));
assertEquals(null, TEST.query(TemporalQueries.localTime()));
assertEquals(null, TEST.query(TemporalQueries.offset()));
assertEquals(null, TEST.query(TemporalQueries.precision()));
assertEquals(ChronoUnit.WEEKS, TEST.query(TemporalQueries.precision()));
assertEquals(null, TEST.query(TemporalQueries.zone()));
assertEquals(null, TEST.query(TemporalQueries.zoneId()));
}
Expand Down