本文整理汇总了Java中java.time.DateTimeException类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeException类的具体用法?Java DateTimeException怎么用?Java DateTimeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeException类属于java.time包,在下文中一共展示了DateTimeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_resolve_ymd_strict
import java.time.DateTimeException; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, MinguoDate 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) {
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
}
}
}
示例2: test_resolve_eymd
import java.time.DateTimeException; //导入依赖的package包/类
@Test(dataProvider = "resolve_eymd")
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
Map<TemporalField, Long> fieldValues = new HashMap<>();
fieldValues.put(ChronoField.ERA, (long) era.getValue());
fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
if (expected != null) {
JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
assertEquals(date, expected);
assertEquals(fieldValues.size(), 0);
} else {
try {
JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
fail("Should have failed");
} catch (DateTimeException ex) {
// expected
}
}
}
示例3: resolveYMD
import java.time.DateTimeException; //导入依赖的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);
}
示例4: test_resolve_ymd_strict
import java.time.DateTimeException; //导入依赖的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
}
}
}
示例5: format
import java.time.DateTimeException; //导入依赖的package包/类
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
int preLen = buf.length();
if (printerParser.format(context, buf) == false) {
return false;
}
int len = buf.length() - preLen;
if (len > padWidth) {
throw new DateTimeException(
"Cannot print as output of " + len + " characters exceeds pad width of " + padWidth);
}
for (int i = 0; i < padWidth - len; i++) {
buf.insert(preLen, padChar);
}
return true;
}
示例6: test_resolve_ymaa_strict
import java.time.DateTimeException; //导入依赖的package包/类
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, ThaiBuddhistDate 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) {
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
}
}
}
示例7: test_resolve_yearOfEra
import java.time.DateTimeException; //导入依赖的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
}
}
}
示例8: data_adjustInto
import java.time.DateTimeException; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
return new Object[][]{
{LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null},
{LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null},
{LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null},
{LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null},
{LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null},
{LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null},
{LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null},
{LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
{LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null},
{LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
{LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class},
{LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
{LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class},
};
}
示例9: data_adjustInto
import java.time.DateTimeException; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
return new Object[][]{
{Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
{Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
{Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
{Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
{Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},
{Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
{Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
{Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
{Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},
{Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
{Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},
};
}
示例10: crossCheck
import java.time.DateTimeException; //导入依赖的package包/类
private void crossCheck(TemporalAccessor target) {
for (Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator(); it.hasNext(); ) {
Entry<TemporalField, Long> entry = it.next();
TemporalField field = entry.getKey();
if (target.isSupported(field)) {
long val1;
try {
val1 = target.getLong(field);
} catch (RuntimeException ex) {
continue;
}
long val2 = entry.getValue();
if (val1 != val2) {
throw new DateTimeException("Conflict found: Field " + field + " " + val1 +
" differs from " + field + " " + val2 + " derived from " + target);
}
it.remove();
}
}
}
示例11: test_resolve_yd_smart
import java.time.DateTimeException; //导入依赖的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
}
}
}
示例12: test_factory_string_invalid
import java.time.DateTimeException; //导入依赖的package包/类
@Test
public void test_factory_string_invalid() {
String[] values = new String[] {
"","A","B","C","D","E","F","G","H","I","J","K","L","M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","ZZ",
"0", "+0:00","+00:0","+0:0",
"+000","+00000",
"+0:00:00","+00:0:00","+00:00:0","+0:0:0","+0:0:00","+00:0:0","+0:00:0",
"1", "+01_00","+01;00","[email protected]","+01:AA",
"+19","+19:00","+18:01","+18:00:01","+1801","+180001",
"-0:00","-00:0","-0:0",
"-000","-00000",
"-0:00:00","-00:0:00","-00:00:0","-0:0:0","-0:0:00","-00:0:0","-0:00:0",
"-19","-19:00","-18:01","-18:00:01","-1801","-180001",
"-01_00","-01;00","[email protected]","-01:AA",
"@01:00",
};
for (int i = 0; i < values.length; i++) {
try {
ZoneOffset.of(values[i]);
fail("Should have failed:" + values[i]);
} catch (DateTimeException ex) {
// expected
}
}
}
示例13: data_adjustInto
import java.time.DateTimeException; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
return new Object[][]{
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
{OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
{OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
{OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},
};
}
示例14: data_adjustInto
import java.time.DateTimeException; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
return new Object[][]{
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
{OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MAX.toLocalDateTime(), ZoneOffset.ofHours(-18)), null},
{OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MIN.toLocalDateTime(), ZoneOffset.ofHours(18)), null},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE),
ZonedDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZONE_GAZA), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_GAZA), null},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
{OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null, null, NullPointerException.class},
};
}
示例15: periodUntil
import java.time.DateTimeException; //导入依赖的package包/类
@Override
public long periodUntil(DateTime endDateTime, PeriodUnit unit) {
if (endDateTime instanceof ChronoZonedDateTime == false) {
throw new DateTimeException("Unable to calculate period between objects of two different types");
}
@SuppressWarnings("unchecked")
ChronoZonedDateTime<C> end = (ChronoZonedDateTime<C>) endDateTime;
if (getDate().getChrono().equals(end.getDate().getChrono()) == false) {
throw new DateTimeException("Unable to calculate period between two different chronologies");
}
if (unit instanceof ChronoUnit) {
end = end.withZoneSameInstant(this.offset);
return this.dateTime.periodUntil(end.getDateTime(), unit);
}
return unit.between(this, endDateTime).getAmount();
}