本文整理了Java中java.time.temporal.Temporal.query()
方法的一些代码示例,展示了Temporal.query()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Temporal.query()
方法的具体详情如下:
包路径:java.time.temporal.Temporal
类名称:Temporal
方法名:query
暂无
代码示例来源:origin: neo4j/neo4j
@Override
public <R> R query( TemporalQuery<R> query )
{
return temporal().query( query );
}
代码示例来源:origin: neo4j/neo4j
final LocalDate expectedDate = ((Temporal) expectedValue).query( TemporalQueries.localDate() );
final LocalTime expectedTime = ((Temporal) expectedValue).query( TemporalQueries.localTime() );
final ZoneId expectedZoneId = ((Temporal) expectedValue).query( TemporalQueries.zone() );
LocalDate actualDate = ((Temporal) actualValue).query( TemporalQueries.localDate() );
LocalTime actualTime = ((Temporal) actualValue).query( TemporalQueries.localTime() );
ZoneId actualZoneId = ((Temporal) actualValue).query( TemporalQueries.zone() );
代码示例来源:origin: org.neo4j/neo4j-values
@Override
public <R> R query( TemporalQuery<R> query )
{
return temporal().query( query );
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* Obtains an instance consisting of the amount of time between two temporals.
* <p>
* The start is included, but the end is not.
* The result of this method can be negative if the end is before the start.
* <p>
* The calculation examines the temporals and extracts {@link LocalDate} and {@link LocalTime}.
* If the time is missing, it will be defaulted to midnight.
* If one date is missing, it will be defaulted to the other date.
* It then finds the amount of time between the two dates and between the two times.
*
* @param startInclusive the start, inclusive, not null
* @param endExclusive the end, exclusive, not null
* @return the number of days between this date and the end date, not null
*/
public static PeriodDuration between(Temporal startInclusive, Temporal endExclusive) {
LocalDate startDate = startInclusive.query(TemporalQueries.localDate());
LocalDate endDate = endExclusive.query(TemporalQueries.localDate());
Period period = Period.ZERO;
if (startDate != null && endDate != null) {
period = Period.between(startDate, endDate);
}
LocalTime startTime = startInclusive.query(TemporalQueries.localTime());
LocalTime endTime = endExclusive.query(TemporalQueries.localTime());
startTime = startTime != null ? startTime : LocalTime.MIDNIGHT;
endTime = endTime != null ? endTime : LocalTime.MIDNIGHT;
Duration duration = Duration.between(startTime, endTime);
return PeriodDuration.of(period, duration);
}
代码示例来源:origin: eXparity/hamcrest-date
@Override
protected boolean matchesSafely(final T actual, final Description mismatchDesc) {
if (!this.adapter.asTemporal(actual, zone).query(localDate()).isLeapYear()) {
mismatchDesc.appendText("the date " + this.formatter.describe(actual) + " is not a leap year");
return false;
} else {
return true;
}
}
代码示例来源:origin: org.threeten/threeten-extra
/**
* 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.
*
* @param <R> the type of the result
* @param query the query to invoke, not null
* @return the query result, null may be returned (defined by the query)
* @throws DateTimeException if unable to query (defined by the query)
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
*/
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) QUARTER_YEARS;
}
return Temporal.super.query(query);
}
代码示例来源:origin: agrestio/agrest
@Override
protected T valueNonNull(JsonNode node) {
Temporal temporal = ISODateParser.parser().fromString(node.asText());
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(0);
ZoneId zone = temporal.query(TemporalQueries.zone());
if (zone != null) {
calendar.setTimeZone(TimeZone.getTimeZone(zone));
}
if (temporal.isSupported(ChronoField.YEAR)) {
int year = temporal.get(ChronoField.YEAR);
int monthOfYear = temporal.get(ChronoField.MONTH_OF_YEAR);
int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
calendar.set(year, --monthOfYear, dayOfMonth);
}
if (temporal.isSupported(ChronoField.HOUR_OF_DAY)) {
int hours = temporal.get(ChronoField.HOUR_OF_DAY);
int minutes = temporal.get(ChronoField.MINUTE_OF_HOUR);
int seconds = temporal.get(ChronoField.SECOND_OF_MINUTE);
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
}
if (temporal.isSupported(ChronoField.MILLI_OF_SECOND)) {
int millis = temporal.get(ChronoField.MILLI_OF_SECOND);
calendar.setTimeInMillis(calendar.getTimeInMillis() + millis);
}
return normalizer.apply(calendar.getTime());
}
代码示例来源:origin: com.nhl.link.rest/link-rest-base
@Override
protected T valueNonNull(JsonNode node) {
Temporal temporal = ISODateParser.parser().fromString(node.asText());
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeInMillis(0);
ZoneId zone = temporal.query(TemporalQueries.zone());
if (zone != null) {
calendar.setTimeZone(TimeZone.getTimeZone(zone));
}
if (temporal.isSupported(ChronoField.YEAR)) {
int year = temporal.get(ChronoField.YEAR);
int monthOfYear = temporal.get(ChronoField.MONTH_OF_YEAR);
int dayOfMonth = temporal.get(ChronoField.DAY_OF_MONTH);
calendar.set(year, --monthOfYear, dayOfMonth);
}
if (temporal.isSupported(ChronoField.HOUR_OF_DAY)) {
int hours = temporal.get(ChronoField.HOUR_OF_DAY);
int minutes = temporal.get(ChronoField.MINUTE_OF_HOUR);
int seconds = temporal.get(ChronoField.SECOND_OF_MINUTE);
calendar.set(Calendar.HOUR_OF_DAY, hours);
calendar.set(Calendar.MINUTE, minutes);
calendar.set(Calendar.SECOND, seconds);
}
if (temporal.isSupported(ChronoField.MILLI_OF_SECOND)) {
int millis = temporal.get(ChronoField.MILLI_OF_SECOND);
calendar.setTimeInMillis(calendar.getTimeInMillis() + millis);
}
return normalizer.apply(calendar.getTime());
}
代码示例来源:origin: com.github.seratch/java-time-backport
@Override
public Temporal addTo(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());
}
if (years != 0) {
temporal = temporal.plus(years, YEARS);
}
if (months != 0) {
temporal = temporal.plus(months, MONTHS);
}
if (days != 0) {
temporal = temporal.plus(days, DAYS);
}
return temporal;
}
代码示例来源:origin: com.github.seratch/java-time-backport
@Override
public Temporal subtractFrom(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());
}
if (years != 0) {
temporal = temporal.minus(years, YEARS);
}
if (months != 0) {
temporal = temporal.minus(months, MONTHS);
}
if (days != 0) {
temporal = temporal.minus(days, DAYS);
}
return temporal;
}
内容来源于网络,如有侵权,请联系作者删除!