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;
}
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations