热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

java.time.temporal.TemporalQueries.localDate()方法的使用及代码示例

本文整理了Java中java.time.temporal.TemporalQueries.localDate()方法的一些代码示例,展示了TemporalQ

本文整理了Java中java.time.temporal.TemporalQueries.localDate()方法的一些代码示例,展示了TemporalQueries.localDate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TemporalQueries.localDate()方法的具体详情如下:
包路径:java.time.temporal.TemporalQueries
类名称:TemporalQueries
方法名:localDate

TemporalQueries.localDate介绍

[英]A query for LocalDate returning null if not found.

This returns a TemporalQuery that can be used to query a temporal object for the local date. The query will return null if the temporal object cannot supply a local date.

The query implementation examines the ChronoField#EPOCH_DAYfield and uses it to create a LocalDate.
[中]如果找不到LocalDate,则返回null的查询。
这将返回一个临时查询,可用于查询本地日期的临时对象。如果时态对象不能提供本地日期,查询将返回null。
查询实现检查ChronoField#EPOCH_DAYfield并使用它创建LocalDate。

代码示例

代码示例来源: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.threeten/threeten-extra

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) isoDate;
}
return super.query(query);
}

代码示例来源:origin: com.nhl.link.rest/link-rest-base

private Optional getLocalDate(TemporalAccessor parsed) {
return Optional.ofNullable(parsed.query(TemporalQueries.localDate()));
}

代码示例来源:origin: agrestio/agrest

private Optional getLocalDate(TemporalAccessor parsed) {
return Optional.ofNullable(parsed.query(TemporalQueries.localDate()));
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
* Queries this date-time using the specified query.
*


* This queries this date-time 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.
*


* 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 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 // override for Javadoc
public R query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) toLocalDate();
}
return super.query(query);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
* Queries this date using the specified query.
*


* 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.
*


* 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 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 query(TemporalQuery query) {
if (query == TemporalQueries.localDate()) {
return (R) this;
}
return super.query(query);
}

代码示例来源:origin: com.github.seratch/java-time-backport

/**
* Obtains an instance of {@code LocalDate} from a temporal object.
*


* A {@code TemporalAccessor} represents some form of date and time information.
* This factory converts the arbitrary temporal object to an instance of {@code LocalDate}.
*


* The conversion uses the {@link TemporalQueries#localDate()} query, which relies
* on extracting the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field.
*


* This method matches the signature of the functional interface {@link TemporalQuery}
* allowing it to be used as a query via method reference, {@code LocalDate::from}.
*
* @param temporal the temporal object to convert, not null
* @return the local date, not null
* @throws DateTimeException if unable to convert to a {@code LocalDate}
*/
public static LocalDate from(TemporalAccessor temporal) {
LocalDate date = temporal.query(TemporalQueries.localDate());
if (date == null) {
throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " +
temporal + ", type " + temporal.getClass().getName());
}
return date;
}

代码示例来源: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: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

query == TemporalQueries.localDate()) {
return null;

代码示例来源:origin: com.github.seratch/java-time-backport

} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
} else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;

代码示例来源:origin: youtongluan/sumk

@Override
public SumkDate queryFrom(TemporalAccessor temporal) {
if (temporal instanceof LocalDateTime) {
return SumkDate.of((LocalDateTime) temporal);
} else if (temporal instanceof ZonedDateTime) {
LocalDateTime dt = ((ZonedDateTime) temporal).toLocalDateTime();
return SumkDate.of(dt);
} else if (temporal instanceof OffsetDateTime) {
LocalDateTime dt = ((OffsetDateTime) temporal).toLocalDateTime();
return SumkDate.of(dt);
}
LocalDate date = temporal.query(TemporalQueries.localDate());
LocalTime time = temporal.query(TemporalQueries.localTime());
if (date == null && time == null) {
return null;
}
return SumkDate.of(date, time);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.DAYS;
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toEpochDay());
} else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
return super.query(query);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.zoneId()) {
return (R) zone;
} else if (query == TemporalQueries.chronology()) {
return (R) chrono;
} else if (query == TemporalQueries.localDate()) {
return date != null ? (R) LocalDate.from(date) : null;
} else if (query == TemporalQueries.localTime()) {
return (R) time;
} else if (query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return query.queryFrom(this);
} else if (query == TemporalQueries.precision()) {
return null; // not a complete date/time
}
// inline TemporalAccessor.super.query(query) as an optimization
// non-JDK classes are not permitted to make this optimization
return query.queryFrom(this);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay());
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
} else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
return super.query(query);
}

代码示例来源:origin: com.github.seratch/java-time-backport

@SuppressWarnings("unchecked")
@Override
public R query(TemporalQuery query) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) {
return (R) getZone();
} else if (query == TemporalQueries.chronology()) {
return (R) toLocalDate().getChronology();
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
} else if (query == TemporalQueries.offset()) {
return (R) getOffset();
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay());
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
}
return super.query(query);
}

推荐阅读
author-avatar
小邵Bans_530
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有