本文整理汇总了Java中org.threeten.bp.DateTimeException类的典型用法代码示例。如果您正苦于以下问题:Java DateTimeException类的具体用法?Java DateTimeException怎么用?Java DateTimeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeException类属于org.threeten.bp包,在下文中一共展示了DateTimeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequirements
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Override
public Set<ValueRequirement> getRequirements(final FunctionCompilationContext context, final ComputationTarget target, final ValueRequirement desiredValue) {
final ValueProperties constraints = desiredValue.getConstraints();
if (!OpenGammaCompilationContext.isPermissive(context)) {
final String date = constraints.getStrictValue(PROPERTY_DATE);
if (date == null) {
s_logger.error("Must supply a date from which to calculate the cash-flows");
return null;
}
try {
LocalDate.parse(date);
} catch (final DateTimeException e) {
s_logger.error("Could not parse date {} - must be in form YYYY-MM-DD", date);
return null;
}
}
final FinancialSecurity security = (FinancialSecurity) target.getSecurity();
final InstrumentDefinition<?> definition = security.accept(_visitor);
return _definitionConverter.getConversionTimeSeriesRequirements(security, definition);
}
示例2: provider_sample_isoDate
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@DataProvider(name="sample_isoDate")
Object[][] provider_sample_isoDate() {
return new Object[][]{
{2008, null, null, null, null, null, DateTimeException.class},
{null, 6, null, null, null, null, DateTimeException.class},
{null, null, 30, null, null, null, DateTimeException.class},
{null, null, null, "+01:00", null, null, DateTimeException.class},
{null, null, null, null, "Europe/Paris", null, DateTimeException.class},
{2008, 6, null, null, null, null, DateTimeException.class},
{null, 6, 30, null, null, null, DateTimeException.class},
{2008, 6, 30, null, null, "2008-06-30", null},
{2008, 6, 30, "+01:00", null, "2008-06-30+01:00", null},
{2008, 6, 30, "+01:00", "Europe/Paris", "2008-06-30+01:00", null},
{2008, 6, 30, null, "Europe/Paris", "2008-06-30", null},
{123456, 6, 30, "+01:00", "Europe/Paris", "+123456-06-30+01:00", null},
};
}
示例3: provider_sample_isoLocalDate
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@DataProvider(name="sample_isoLocalDate")
Object[][] provider_sample_isoLocalDate() {
return new Object[][]{
{2008, null, null, null, null, null, DateTimeException.class},
{null, 6, null, null, null, null, DateTimeException.class},
{null, null, 30, null, null, null, DateTimeException.class},
{null, null, null, "+01:00", null, null, DateTimeException.class},
{null, null, null, null, "Europe/Paris", null, DateTimeException.class},
{2008, 6, null, null, null, null, DateTimeException.class},
{null, 6, 30, null, null, null, DateTimeException.class},
{2008, 6, 30, null, null, "2008-06-30", null},
{2008, 6, 30, "+01:00", null, "2008-06-30", null},
{2008, 6, 30, "+01:00", "Europe/Paris", "2008-06-30", null},
{2008, 6, 30, null, "Europe/Paris", "2008-06-30", null},
{123456, 6, 30, null, null, "+123456-06-30", null},
};
}
示例4: crossCheck
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
private void crossCheck(TemporalAccessor temporal) {
Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator();
while (it.hasNext()) {
Entry<TemporalField, Long> entry = it.next();
TemporalField field = entry.getKey();
long value = entry.getValue();
if (temporal.isSupported(field)) {
long temporalValue;
try {
temporalValue = temporal.getLong(field);
} catch (RuntimeException ex) {
continue;
}
if (temporalValue != value) {
throw new DateTimeException("Cross check failed: " +
field + " " + temporalValue + " vs " + field + " " + value);
}
it.remove();
}
}
}
示例5: formatTo
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
/**
* Formats a date-time object to an {@code Appendable} using this formatter.
* <p>
* This formats the date-time to the specified destination.
* {@link Appendable} is a general purpose interface that is implemented by all
* key character output classes including {@code StringBuffer}, {@code StringBuilder},
* {@code PrintStream} and {@code Writer}.
* <p>
* Although {@code Appendable} methods throw an {@code IOException}, this method does not.
* Instead, any {@code IOException} is wrapped in a runtime exception.
*
* @param temporal the temporal object to print, not null
* @param appendable the appendable to print to, not null
* @throws DateTimeException if an error occurs during formatting
*/
public void formatTo(TemporalAccessor temporal, Appendable appendable) {
Jdk8Methods.requireNonNull(temporal, "temporal");
Jdk8Methods.requireNonNull(appendable, "appendable");
try {
DateTimePrintContext context = new DateTimePrintContext(temporal, this);
if (appendable instanceof StringBuilder) {
printerParser.print(context, (StringBuilder) appendable);
} else {
// buffer output to avoid writing to appendable in case of error
StringBuilder buf = new StringBuilder(32);
printerParser.print(context, buf);
appendable.append(buf);
}
} catch (IOException ex) {
throw new DateTimeException(ex.getMessage(), ex);
}
}
示例6: print
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
int preLen = buf.length();
if (printerParser.print(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;
}
示例7: test_pad_NEVER
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_NEVER(int minPad, int maxPad, long value, String result) throws Exception {
printContext.setDateTime(new MockFieldValue(DAY_OF_MONTH, value));
NumberPrinterParser pp = new NumberPrinterParser(DAY_OF_MONTH, minPad, maxPad, SignStyle.NEVER);
try {
pp.print(printContext, buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例8: test_pad_EXCEEDS_PAD
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_EXCEEDS_PAD(int minPad, int maxPad, long value, String result) throws Exception {
printContext.setDateTime(new MockFieldValue(DAY_OF_MONTH, value));
NumberPrinterParser pp = new NumberPrinterParser(DAY_OF_MONTH, minPad, maxPad, SignStyle.EXCEEDS_PAD);
try {
pp.print(printContext, buf);
if (result == null) {
fail("Expected exception");
return; // unreachable
}
if (result.length() > minPad || value < 0) {
result = (value < 0 ? "-" + result : "+" + result);
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例9: ofYearDay
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
/**
* Obtains a {@code JapaneseDate} representing a date in the Japanese calendar
* system from the era, year-of-era and day-of-year fields.
* <p>
* This returns a {@code JapaneseDate} with the specified fields.
* The day must be valid for the year, otherwise an exception will be thrown.
* The Japanese day-of-year is reset when the era changes.
*
* @param era the Japanese era, not null
* @param yearOfEra the Japanese year-of-era
* @param dayOfYear the Japanese day-of-year, from 1 to 31
* @return the date in Japanese calendar system, not null
* @throws DateTimeException if the value of any field is out of range,
* or if the day-of-year is invalid for the year
*/
static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) {
Jdk8Methods.requireNonNull(era, "era");
if (yearOfEra < 1) {
throw new DateTimeException("Invalid YearOfEra: " + yearOfEra);
}
LocalDate eraStartDate = era.startDate();
LocalDate eraEndDate = era.endDate();
if (yearOfEra == 1) {
dayOfYear += eraStartDate.getDayOfYear() - 1;
if (dayOfYear > eraStartDate.lengthOfYear()) {
throw new DateTimeException("DayOfYear exceeds maximum allowed in the first year of era " + era);
}
}
int yearOffset = eraStartDate.getYear() - 1;
LocalDate isoDate = LocalDate.ofYearDay(yearOfEra + yearOffset, dayOfYear);
if (isoDate.isBefore(eraStartDate) || isoDate.isAfter(eraEndDate)) {
throw new DateTimeException("Requested date is outside bounds of era " + era);
}
return new JapaneseDate(era, yearOfEra, isoDate);
}
示例10: zonedDateTime
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
/**
* Obtains a zoned date-time in this chronology from another temporal object.
* <p>
* This creates a date-time in this chronology based on the specified {@code TemporalAccessor}.
* <p>
* This should obtain a {@code ZoneId} using {@link ZoneId#from(TemporalAccessor)}.
* The date-time should be obtained by obtaining an {@code Instant}.
* If that fails, the local date-time should be used.
*
* @param temporal the temporal object to convert, not null
* @return the zoned date-time in this chronology, not null
* @throws DateTimeException if unable to create the date-time
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) {
try {
ZoneId zone = ZoneId.from(temporal);
try {
Instant instant = Instant.from(temporal);
return zonedDateTime(instant, zone);
} catch (DateTimeException ex1) {
ChronoLocalDateTime cldt = localDateTime(temporal);
ChronoLocalDateTimeImpl cldtImpl = ensureChronoLocalDateTime(cldt);
return ChronoZonedDateTimeImpl.ofBest(cldtImpl, zone, null);
}
} catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
}
}
示例11: registerEra
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
/**
* Registers an additional instance of {@code JapaneseEra}.
* <p>
* A new Japanese era can begin at any time.
* This method allows one new era to be registered without the need for a new library version.
* If needed, callers should assign the result to a static variable accessible
* across the application. This must be done once, in early startup code.
* <p>
* NOTE: This method does not exist in Java SE 8.
*
* @param since the date representing the first date of the era, validated not null
* @param name the name
* @return the {@code JapaneseEra} singleton, not null
* @throws DateTimeException if an additional era has already been registered
*/
public static JapaneseEra registerEra(LocalDate since, String name) {
JapaneseEra[] known = KNOWN_ERAS.get();
if (known.length > 4) {
throw new DateTimeException("Only one additional Japanese era can be added");
}
Jdk8Methods.requireNonNull(since, "since");
Jdk8Methods.requireNonNull(name, "name");
if (!since.isAfter(HEISEI.since)) {
throw new DateTimeException("Invalid since date for additional Japanese era, must be after Heisei");
}
JapaneseEra era = new JapaneseEra(ADDITIONAL_VALUE, since, name);
JapaneseEra[] newArray = Arrays.copyOf(known, 5);
newArray[4] = era;
if (!KNOWN_ERAS.compareAndSet(known, newArray)) {
throw new DateTimeException("Only one additional Japanese era can be added");
}
return era;
}
示例12: test_pivot
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Test(dataProvider="Pivot")
public void test_pivot(int width, int baseValue, int value, String result) throws Exception {
printContext.setDateTime(new MockFieldValue(YEAR, value));
ReducedPrinterParser pp = new ReducedPrinterParser(YEAR, width, width, baseValue, null);
try {
pp.print(printContext, buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), result);
} catch (DateTimeException ex) {
if (result == null || value < 0) {
assertEquals(ex.getMessage().contains(YEAR.toString()), true);
} else {
throw ex;
}
}
}
示例13: test_pad_NORMAL
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@Test(dataProvider="Pad")
public void test_pad_NORMAL(int minPad, int maxPad, long value, String result) throws Exception {
printContext.setDateTime(new MockFieldValue(DAY_OF_MONTH, value));
NumberPrinterParser pp = new NumberPrinterParser(DAY_OF_MONTH, minPad, maxPad, SignStyle.NORMAL);
try {
pp.print(printContext, buf);
if (result == null) {
fail("Expected exception");
}
assertEquals(buf.toString(), (value < 0 ? "-" + result : result));
} catch (DateTimeException ex) {
if (result != null) {
throw ex;
}
assertEquals(ex.getMessage().contains(DAY_OF_MONTH.toString()), true);
}
}
示例14: parseInstantString
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
/**
* Parses a version-correction {@code Instant} from a standard string representation.
* <p>
* The string representation must be either {@code LATEST} for null,
* or the ISO-8601 representation of the desired {@code Instant}.
*
* @param instantStr the instant string, null treated as latest
* @return the instant, not null
*/
private static Instant parseInstantString(String instantStr) {
if (instantStr == null || instantStr.equals("LATEST")) {
return null;
} else {
try {
return Instant.parse(instantStr);
} catch (DateTimeException ex) {
throw new IllegalArgumentException(ex);
}
}
}
示例15: adjustInto
import org.threeten.bp.DateTimeException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <R extends Temporal> R adjustInto(R dateTime, long newValue) {
if (range().isValidValue(newValue) == false) {
throw new DateTimeException("Invalid value: " + name + " " + newValue);
}
return (R) dateTime.with(EPOCH_DAY, Jdk8Methods.safeSubtract(newValue, offset));
}