Search in sources :

Example 96 with ZonedDateTime

use of java.time.ZonedDateTime in project questdb by bluestreak01.

the class TimeZoneRulesImplTest method testCompatibility.

@Test
public void testCompatibility() {
    Set<String> allZones = ZoneId.getAvailableZoneIds();
    List<String> zoneList = new ArrayList<>(allZones);
    Collections.sort(zoneList);
    List<ZoneId> zones = new ArrayList<>(zoneList.size());
    List<TimeZoneRulesImpl> zoneRules = new ArrayList<>(zoneList.size());
    for (String z : zoneList) {
        ZoneId zone = ZoneId.of(z);
        zones.add(zone);
        zoneRules.add(new TimeZoneRulesImpl(z, zone.getRules()));
    }
    long micros = Dates.toMillis(1900, 1, 1, 0, 0);
    long deadline = Dates.toMillis(2115, 12, 31, 0, 0);
    while (micros < deadline) {
        int y = Dates.getYear(micros);
        boolean leap = Dates.isLeapYear(y);
        int m = Dates.getMonthOfYear(micros, y, leap);
        int d = Dates.getDayOfMonth(micros, y, m, leap);
        LocalDateTime dt = LocalDateTime.of(y, m, d, 0, 0);
        for (int i = 0, n = zones.size(); i < n; i++) {
            ZoneId zone = zones.get(i);
            TimeZoneRulesImpl rules = zoneRules.get(i);
            ZonedDateTime zdt = dt.atZone(zone);
            long expected = zdt.getOffset().getTotalSeconds();
            // find out how much algo added to datetime itself
            long changed = Dates.toMillis(zdt.getYear(), zdt.getMonthValue(), zdt.getDayOfMonth(), zdt.getHour(), zdt.getMinute()) + zdt.getSecond() * Dates.SECOND_MILLIS;
            // add any extra time
            expected += (changed - micros) / Dates.SECOND_MILLIS;
            long offset = rules.getOffset(micros, y, leap);
            try {
                Assert.assertEquals(expected, offset / Dates.SECOND_MILLIS);
            } catch (Throwable e) {
                System.out.println(zone.getId() + "; " + zdt + "; " + Dates.toString(micros + offset));
                System.out.println("e: " + expected + "; a: " + offset);
                System.out.println(dt);
                System.out.println(Dates.toString(micros));
                throw e;
            }
        }
        micros += Dates.DAY_MILLIS;
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) ArrayList(java.util.ArrayList) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 97 with ZonedDateTime

use of java.time.ZonedDateTime in project nifi by apache.

the class TimeAdapter method marshal.

@Override
public String marshal(Date date) throws Exception {
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_TIME_FORMAT, Locale.US);
    final ZonedDateTime localDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZONE_ID);
    return formatter.format(localDateTime);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 98 with ZonedDateTime

use of java.time.ZonedDateTime in project nifi by apache.

the class TimezoneAdapter method marshal.

@Override
public String marshal(Date date) throws Exception {
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT, Locale.US);
    final ZonedDateTime localDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZONE_ID);
    return formatter.format(localDateTime);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 99 with ZonedDateTime

use of java.time.ZonedDateTime in project fess by codelibs.

the class ClickLog method addFieldToSource.

@Override
protected void addFieldToSource(final Map<String, Object> sourceMap, final String field, final Object value) {
    if (value instanceof LocalDateTime) {
        final LocalDateTime ldt = (LocalDateTime) value;
        final ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
        super.addFieldToSource(sourceMap, field, DateTimeFormatter.ISO_INSTANT.format(zdt));
    } else {
        super.addFieldToSource(sourceMap, field, value);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZonedDateTime(java.time.ZonedDateTime)

Example 100 with ZonedDateTime

use of java.time.ZonedDateTime in project fess by codelibs.

the class FavoriteLog method addFieldToSource.

@Override
protected void addFieldToSource(final Map<String, Object> sourceMap, final String field, final Object value) {
    if (value instanceof LocalDateTime) {
        final LocalDateTime ldt = (LocalDateTime) value;
        final ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
        super.addFieldToSource(sourceMap, field, DateTimeFormatter.ISO_INSTANT.format(zdt));
    } else {
        super.addFieldToSource(sourceMap, field, value);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ZonedDateTime(java.time.ZonedDateTime)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1375 Test (org.junit.Test)570 Test (org.testng.annotations.Test)182 LocalDateTime (java.time.LocalDateTime)136 ZoneId (java.time.ZoneId)122 Instant (java.time.Instant)112 ArrayList (java.util.ArrayList)102 Test (org.junit.jupiter.api.Test)93 LocalDate (java.time.LocalDate)84 DateTimeFormatter (java.time.format.DateTimeFormatter)77 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)76 List (java.util.List)75 Date (java.util.Date)63 IOException (java.io.IOException)58 UUID (java.util.UUID)58 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)53 HashMap (java.util.HashMap)46 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)43