Search in sources :

Example 41 with DateTimeException

use of java.time.DateTimeException in project drools by kiegroup.

the class SecondsDiffFunction method invoke.

public FEELFnResult<BigDecimal> invoke(@ParameterName("datetime1") String datetime1, @ParameterName("datetime2") String datetime2) {
    if (datetime1 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime1", "cannot be null"));
    }
    if (datetime2 == null) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime2", "cannot be null"));
    }
    try {
        TemporalAccessor dt1 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime1).cata(BuiltInType.justNull(), Function.identity());
        TemporalAccessor dt2 = BuiltInFunctions.getFunction(DateAndTimeFunction.class).invoke(datetime2).cata(BuiltInType.justNull(), Function.identity());
        return invoke(dt1, dt2);
    } catch (DateTimeException e) {
        return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "datetime", "invalid 'date' or 'date and time' parameter", e));
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent)

Example 42 with DateTimeException

use of java.time.DateTimeException in project JFoenix by jfoenixadmin.

the class JFXDatePickerContent method formatMonth.

private String formatMonth(YearMonth yearMonth) {
    try {
        Chronology chrono = getPrimaryChronology();
        ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1));
        String str = monthFormatter.withLocale(getLocale()).withChronology(chrono).format(cDate);
        return str;
    } catch (DateTimeException ex) {
        // Date is out of range.
        return "";
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeException(java.time.DateTimeException) Chronology(java.time.chrono.Chronology)

Example 43 with DateTimeException

use of java.time.DateTimeException in project JFoenix by jfoenixadmin.

the class JFXDatePickerContent method formatYear.

private String formatYear(YearMonth yearMonth) {
    try {
        Chronology chrono = getPrimaryChronology();
        ChronoLocalDate cDate = chrono.date(yearMonth.atDay(1));
        String str = yearFormatter.withLocale(getLocale()).withChronology(chrono).withDecimalStyle(DecimalStyle.of(getLocale())).format(cDate);
        return str;
    } catch (DateTimeException ex) {
        // Date is out of range.
        return "";
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) DateTimeException(java.time.DateTimeException) Chronology(java.time.chrono.Chronology)

Example 44 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKIsoChronology method test_resolve_yd_strict.

@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_strict(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 (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
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 45 with DateTimeException

use of java.time.DateTimeException in project jdk8u_jdk by JetBrains.

the class TCKIsoChronology method test_resolve_yearOfEra.

@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
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

DateTimeException (java.time.DateTimeException)88 Test (org.testng.annotations.Test)58 TemporalField (java.time.temporal.TemporalField)48 HashMap (java.util.HashMap)34 LocalDate (java.time.LocalDate)20 TemporalAccessor (java.time.temporal.TemporalAccessor)20 DateTimeFormatter (java.time.format.DateTimeFormatter)13 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 MinguoDate (java.time.chrono.MinguoDate)7 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)7 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)7 MockFieldValue (test.java.time.temporal.MockFieldValue)7 HijrahDate (java.time.chrono.HijrahDate)6 ChronoLocalDate (java.time.chrono.ChronoLocalDate)5 JapaneseDate (java.time.chrono.JapaneseDate)5 Chronology (java.time.chrono.Chronology)4 IOException (java.io.IOException)3 LocalTime (java.time.LocalTime)3 WeekFields (java.time.temporal.WeekFields)3 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)3