本文整理汇总了Java中java.time.format.ResolverStyle类的典型用法代码示例。如果您正苦于以下问题:Java ResolverStyle类的具体用法?Java ResolverStyle怎么用?Java ResolverStyle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResolverStyle类属于java.time.format包,在下文中一共展示了ResolverStyle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: resolveYMD
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Override // override for performance
LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH));
if (resolverStyle == ResolverStyle.SMART) { // previous valid
if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
dom = Math.min(dom, 30);
} else if (moy == 2) {
dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y)));
}
}
return LocalDate.of(y, moy, dom);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:IsoChronology.java
示例2: resolveYMD
import java.time.format.ResolverStyle; //导入依赖的package包/类
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
}
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
ValueRange domRange = range(DAY_OF_MONTH);
int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART) { // previous valid
try {
return date(y, moy, dom);
} catch (DateTimeException ex) {
return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
}
}
return date(y, moy, dom);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:AbstractChronology.java
示例3: test_resolveFourToDateTime
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveFourToTime")
public void test_resolveFourToDateTime(ResolverStyle style,
long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.parseDefaulting(YEAR, 2012).parseDefaulting(MONTH_OF_YEAR, 6).parseDefaulting(DAY_OF_MONTH, 30)
.parseDefaulting(HOUR_OF_DAY, hour)
.parseDefaulting(MINUTE_OF_HOUR, min)
.parseDefaulting(SECOND_OF_MINUTE, sec)
.parseDefaulting(NANO_OF_SECOND, nano).toFormatter();
ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
if (expectedTime != null && excessPeriod != null) {
LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
for (ResolverStyle s : styles) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TCKDateTimeParseResolver.java
示例4: test_resolve_ymaa_strict
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
if (strict) {
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TCKIsoChronology.java
示例5: test_resolve_ymd_strict
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (strict) {
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKThaiBuddhistChronology.java
示例6: test_resolve_ymaa_smart
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_smart(int y, int m, int w, int d, LocalDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
if (smart) {
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TCKIsoChronology.java
示例7: test_resolve_yearOfEra
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
if (e != null) {
fieldValues.put(ChronoField.ERA, (long) e);
}
if (yoe != null) {
fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
}
if (y != null) {
fieldValues.put(ChronoField.YEAR, (long) y);
}
if (field != null) {
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style);
assertEquals(date, null);
assertEquals(fieldValues.get(field), (Long) expected.longValue());
assertEquals(fieldValues.size(), 1);
} else {
try {
IsoChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:TCKIsoChronology.java
示例8: test_resolveSecondOfDay
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveSecondOfDay")
public void test_resolveSecondOfDay(ResolverStyle style, long value, Integer expectedSecond, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(SECOND_OF_DAY).toFormatter();
if (expectedSecond != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TCKDateTimeParseResolver.java
示例9: test_resolve_ymd_strict
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, LocalDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (strict) {
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKIsoChronology.java
示例10: test_parse_parseLenientWeek_SMART
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "parseLenientWeek")
public void test_parse_parseLenientWeek_SMART(String str, LocalDate expected, boolean smart) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.appendValue(IsoFields.WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(IsoFields.WEEK_OF_WEEK_BASED_YEAR).appendLiteral(':')
.appendValue(DAY_OF_WEEK)
.toFormatter().withResolverStyle(ResolverStyle.SMART);
if (smart) {
LocalDate parsed = LocalDate.parse(str, f);
assertEquals(parsed, expected);
} else {
try {
LocalDate.parse(str, f);
fail("Should have failed");
} catch (DateTimeParseException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKIsoFields.java
示例11: test_resolve_yd_smart
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, MinguoDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
if (smart) {
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKMinguoChronology.java
示例12: test_resolve_yd_smart
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
if (smart) {
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TCKThaiBuddhistChronology.java
示例13: test_resolveThreeToTime
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveFourToTime")
public void test_resolveThreeToTime(ResolverStyle style,
long hour, long min, long sec, long nano, LocalTime expectedTime, Period excessPeriod) {
DateTimeFormatter f = new DateTimeFormatterBuilder()
.parseDefaulting(HOUR_OF_DAY, hour)
.parseDefaulting(MINUTE_OF_HOUR, min)
.parseDefaulting(SECOND_OF_MINUTE, sec).toFormatter();
ResolverStyle[] styles = (style != null ? new ResolverStyle[] {style} : ResolverStyle.values());
for (ResolverStyle s : styles) {
if (expectedTime != null) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
} else {
try {
f.withResolverStyle(style).parse("");
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:TCKDateTimeParseResolver.java
示例14: test_resolve_yearOfEra
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
if (e != null) {
fieldValues.put(ChronoField.ERA, (long) e);
}
if (yoe != null) {
fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
}
if (y != null) {
fieldValues.put(ChronoField.YEAR, (long) y);
}
if (field != null) {
ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
assertEquals(date, null);
assertEquals(fieldValues.get(field), (Long) expected.longValue());
assertEquals(fieldValues.size(), 1);
} else {
try {
ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:TCKThaiBuddhistChronology.java
示例15: test_resolveClockHourOfDay
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveClockHourOfDay")
public void test_resolveClockHourOfDay(ResolverStyle style, long value, Integer expectedHour, int expectedDays) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_DAY).toFormatter();
if (expectedHour != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TCKDateTimeParseResolver.java
示例16: test_resolveClockHourOfAmPm
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveClockHourOfAmPm")
public void test_resolveClockHourOfAmPm(ResolverStyle style, long value, Integer expectedValue) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(CLOCK_HOUR_OF_AMPM).toFormatter();
if (expectedValue != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(CLOCK_HOUR_OF_AMPM), false);
assertEquals(accessor.isSupported(HOUR_OF_AMPM), true);
assertEquals(accessor.getLong(HOUR_OF_AMPM), expectedValue.longValue());
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TCKDateTimeParseResolver.java
示例17: test_resolveAmPm
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider="resolveAmPm")
public void test_resolveAmPm(ResolverStyle style, long value, Integer expectedValue) {
String str = Long.toString(value);
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(AMPM_OF_DAY).toFormatter();
if (expectedValue != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(AMPM_OF_DAY), true);
assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue());
} else {
try {
f.withResolverStyle(style).parse(str);
fail();
} catch (DateTimeParseException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TCKDateTimeParseResolver.java
示例18: test_resolve_ymd_strict
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (strict) {
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TCKJapaneseChronology.java
示例19: test_resolve_ymaa_strict
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, MinguoDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
if (strict) {
MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TCKMinguoChronology.java
示例20: test_resolve_yd_smart
import java.time.format.ResolverStyle; //导入依赖的package包/类
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, LocalDate expected, boolean smart, boolean strict) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.YEAR, (long) y);
fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
if (smart) {
LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKIsoChronology.java
注:本文中的java.time.format.ResolverStyle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论