Search in sources :

Example 91 with LocalTime

use of java.time.LocalTime in project wildfly by wildfly.

the class LocalDateTimeExternalizer method readObject.

@Override
public LocalDateTime readObject(ObjectInput input) throws IOException, ClassNotFoundException {
    LocalDate date = DATE_EXTERNALIZER.readObject(input);
    LocalTime time = TIME_EXTERNALIZER.readObject(input);
    return LocalDateTime.of(date, time);
}
Also used : LocalTime(java.time.LocalTime) LocalDate(java.time.LocalDate)

Example 92 with LocalTime

use of java.time.LocalTime in project felix by apache.

the class ConverterTest method testLocalTime.

@Test
public void testLocalTime() {
    LocalTime lt = LocalTime.now();
    String s = converter.convert(lt).to(String.class);
    assertTrue(s.length() > 0);
    LocalTime lt2 = converter.convert(s).to(LocalTime.class);
    assertEquals(lt, lt2);
}
Also used : LocalTime(java.time.LocalTime) Test(org.junit.Test)

Example 93 with LocalTime

use of java.time.LocalTime in project dbflute-core by dbflute.

the class AbstractConditionQuery method filterConditionValueIfNeeds.

protected Object filterConditionValueIfNeeds(ConditionKey key, Object value, ConditionValue cvalue, String columnDbName, ConditionOption option, ColumnInfo columnInfo) {
    if (value != null && isDatetimePrecisionTruncationOfConditionEnabled(columnDbName)) {
        // null check, just in case
        if (columnInfo.isObjectNativeTypeDate()) {
            // contains Java8 Dates
            final Integer datetimePrecision = columnInfo.getDatetimePrecision();
            if (datetimePrecision == null || datetimePrecision == 0) {
                // non-millisecond date-time
                if (value instanceof LocalDateTime) {
                    // means clear millisecond
                    return ((LocalDateTime) value).truncatedTo(ChronoUnit.SECONDS);
                } else if (value instanceof LocalTime) {
                    // means clear millisecond
                    return ((LocalTime) value).truncatedTo(ChronoUnit.SECONDS);
                } else if (value instanceof Date && !(value instanceof java.sql.Date)) {
                    final Calendar cal = DfTypeUtil.toCalendar(value);
                    DfTypeUtil.clearCalendarMillisecond(cal);
                    return DfTypeUtil.toDate(cal);
                }
            }
        }
    }
    return value;
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Calendar(java.util.Calendar) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 94 with LocalTime

use of java.time.LocalTime in project jphp by jphp-compiler.

the class UXMaterialTimePicker method getValueAsTime.

@Getter
public WrapTime getValueAsTime(Environment env) {
    initFormat();
    LocalTime value = getWrappedObject().getValue();
    if (value == null) {
        return null;
    }
    Instant instant = value.atDate(LocalDate.of(0, 0, 0)).atZone(ZoneId.systemDefault()).toInstant();
    return new WrapTime(env, Date.from(instant));
}
Also used : WrapTime(php.runtime.ext.core.classes.time.WrapTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) Getter(php.runtime.annotation.Reflection.Getter)

Example 95 with LocalTime

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

the class Parsed method resolveFields.

//-----------------------------------------------------------------------
private void resolveFields() {
    // resolve ChronoField
    resolveInstantFields();
    resolveDateFields();
    resolveTimeFields();
    // any lenient date resolution should return epoch-day
    if (fieldValues.size() > 0) {
        int changedCount = 0;
        outer: while (changedCount < 50) {
            for (Map.Entry<TemporalField, Long> entry : fieldValues.entrySet()) {
                TemporalField targetField = entry.getKey();
                TemporalAccessor resolvedObject = targetField.resolve(fieldValues, this, resolverStyle);
                if (resolvedObject != null) {
                    if (resolvedObject instanceof ChronoZonedDateTime) {
                        ChronoZonedDateTime<?> czdt = (ChronoZonedDateTime<?>) resolvedObject;
                        if (zone == null) {
                            zone = czdt.getZone();
                        } else if (zone.equals(czdt.getZone()) == false) {
                            throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + zone);
                        }
                        resolvedObject = czdt.toLocalDateTime();
                    }
                    if (resolvedObject instanceof ChronoLocalDateTime) {
                        ChronoLocalDateTime<?> cldt = (ChronoLocalDateTime<?>) resolvedObject;
                        updateCheckConflict(cldt.toLocalTime(), Period.ZERO);
                        updateCheckConflict(cldt.toLocalDate());
                        changedCount++;
                        // have to restart to avoid concurrent modification
                        continue outer;
                    }
                    if (resolvedObject instanceof ChronoLocalDate) {
                        updateCheckConflict((ChronoLocalDate) resolvedObject);
                        changedCount++;
                        // have to restart to avoid concurrent modification
                        continue outer;
                    }
                    if (resolvedObject instanceof LocalTime) {
                        updateCheckConflict((LocalTime) resolvedObject, Period.ZERO);
                        changedCount++;
                        // have to restart to avoid concurrent modification
                        continue outer;
                    }
                    throw new DateTimeException("Method resolve() can only return ChronoZonedDateTime, " + "ChronoLocalDateTime, ChronoLocalDate or LocalTime");
                } else if (fieldValues.containsKey(targetField) == false) {
                    changedCount++;
                    // have to restart to avoid concurrent modification
                    continue outer;
                }
            }
            break;
        }
        if (changedCount == 50) {
            // catch infinite loops
            throw new DateTimeException("One of the parsed fields has an incorrectly implemented resolve method");
        }
        // if something changed then have to redo ChronoField resolve
        if (changedCount > 0) {
            resolveInstantFields();
            resolveDateFields();
            resolveTimeFields();
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) Entry(java.util.Map.Entry) TemporalField(java.time.temporal.TemporalField) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalTime(java.time.LocalTime) ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime)

Aggregations

LocalTime (java.time.LocalTime)676 Test (org.junit.Test)262 Test (org.testng.annotations.Test)173 LocalDate (java.time.LocalDate)156 LocalDateTime (java.time.LocalDateTime)130 ZonedDateTime (java.time.ZonedDateTime)36 Date (java.util.Date)32 Instant (java.time.Instant)30 OffsetDateTime (java.time.OffsetDateTime)30 DateTimeFormatter (java.time.format.DateTimeFormatter)27 Test (org.junit.jupiter.api.Test)27 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)23 ZoneOffset (java.time.ZoneOffset)23 ZoneId (java.time.ZoneId)22 ArrayList (java.util.ArrayList)19 BigDecimal (java.math.BigDecimal)18 TemporalAccessor (java.time.temporal.TemporalAccessor)18 TemporalAmount (java.time.temporal.TemporalAmount)18 Time (java.sql.Time)17 Clock (java.time.Clock)17