@Override public OffsetDateTime convert(Calendar source) { return calendarToZonedDateTime(source).toOffsetDateTime(); } }
@Override public OffsetDateTime convert(ZonedDateTime source) { return source.toOffsetDateTime(); } }
@Override public OffsetDateTime convert(Calendar source) { return calendarToZonedDateTime(source).toOffsetDateTime(); } }
@Override public OffsetDateTime convert(ZonedDateTime source) { return source.toOffsetDateTime(); } }
@Override public CalendarEventModel.CalendarEventTime apply( Map<String, String> time, TransformerContext context) { if (time == null) { return null; } String dateTimeValue = time.get("dateTime"); String timeZone = time.get("timeZone"); if (dateTimeValue == null || timeZone == null) { return null; } try { OffsetDateTime dateTime = ZonedDateTime.of(LocalDateTime.parse(dateTimeValue), ZoneId.of(timeZone)) .toOffsetDateTime(); return new CalendarEventModel.CalendarEventTime(dateTime, false); } catch (DateTimeException e) { context.problem(e.getMessage()); return null; } } }
/** * Formats {@link LocalDateTime} to be sent to the backend, thus it adds time zone. * Do not use this method in {@link java.sql.ResultSet#getString(int)} * @param localDateTime The local date to format as a String * @return The formatted local date */ public synchronized String toString(LocalDateTime localDateTime) { if (localDateTime.isAfter(MAX_LOCAL_DATETIME)) { return "infinity"; } else if (LocalDateTime.MIN.equals(localDateTime)) { return "-infinity"; } // LocalDateTime is always passed with time zone so backend can decide between timestamp and timestamptz ZonedDateTime zonedDateTime = localDateTime.atZone(getDefaultTz().toZoneId()); return toString(zonedDateTime.toOffsetDateTime()); }
public OffsetDateTime toOffsetDateTime() { return dt.toOffsetDateTime(); }
CalendarEventModel.CalendarEventTime start = new CalendarEventModel.CalendarEventTime( ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false); CalendarEventModel.CalendarEventTime end = new CalendarEventModel.CalendarEventTime( ZonedDateTime.now(ZoneId.of("GMT")).toOffsetDateTime(), false); CalendarEventModel eventModel = new CalendarEventModel(
return ((java.sql.Timestamp)value).toInstant() .atZone(config.getZoneId()) .toOffsetDateTime(); } else { return ((java.sql.Timestamp)value).toLocalDateTime(); return ((java.sql.Timestamp)value).toInstant() .atZone(config.getZoneId()) .toOffsetDateTime(); } else { return OffsetDateTime.parse(value.toString());
@Override public OffsetDateTime convert(Date in, Context context) throws Exception { if (in == null) return null; return in.toInstant().atZone(dateTimeZone).toOffsetDateTime(); } }
@Test public void testLoadJdbcParamsWithConfigLocalDateTime() throws Exception { testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'])", (row) -> assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toLocalDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row"))); ZoneId asiaTokio = ZoneId.of("Asia/Tokyo"); testCall(db, "CALL apoc.load.jdbc('jdbc:derby:derbyDB','SELECT * FROM PERSON WHERE NAME = ?',['John'], {config})", map("config", map("timezone", asiaTokio.toString())), (row) -> { assertEquals( Util.map("NAME", "John", "HIRE_DATE", hireDate.toLocalDate(), "EFFECTIVE_FROM_DATE", effectiveFromDate.toInstant().atZone(asiaTokio).toOffsetDateTime(), "TEST_TIME", time.toLocalTime(), "NULL_DATE", null), row.get("row")); }); }
public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext paramDeserializationContext) throws IOException, JsonProcessingException { if (jsonParser.getText() == null || jsonParser.getText().length() == 0) { return null; } ZonedDateTime dateTime=toDateTime(jsonParser.getText()); return dateTime.toOffsetDateTime(); } }
public static Timestamp fromZonedDateTimeUtc(@Nonnull ZonedDateTime zonedDateTime) { checkNotNull(zonedDateTime, "zonedDateTime"); return fromOffsetDateTimeUtc(zonedDateTime.toOffsetDateTime()); } }
public OffsetTime time(LocalDate from) { if (from == null) { return null; } return from.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime().toOffsetTime(); } public OffsetTime time(OffsetTime from) {
public OffsetTime time(LocalDate from) { if (from == null) { return null; } return from.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime().toOffsetTime(); } public OffsetTime time(OffsetTime from) {
@Override public String toString(final ZonedDateTime value) { checkArgument(value != null); return value.toOffsetDateTime().toString(); } }
/** * Parses the date using the formatter to create * {@link OffsetDateTime} instances. * @param date The date to parse. * @param formatter The formatter to use. */ public OffsetDateTimeOf(final CharSequence date, final DateTimeFormatter formatter) { this.parsed = new UncheckedScalar<>( () -> ZonedDateTime.from(formatter.parse(date)).toOffsetDateTime() ); }
@Override public void serialize(final Object object, final ObjectEncoder encoder) { final ZonedDateTime val = (ZonedDateTime) object; // Make sure we have timezone as (numeric) offset instead of // using zone ID. We do this by invoking toOffsetDateTime(). // This makes the timestamp ISO-8601 compatible and therefore // more portable. encoder.writeStringContents(val.toOffsetDateTime().toString()); } });
public static OffsetDateTime toOffsetDateTime(final String format, final String date) { switch (format) { // the only two formats, as confirmed via e-mail with Zonky employees case "yyyy-MM": return YearMonth.parse(date, YEAR_MONTH) .atDay(1) .atStartOfDay(Defaults.ZONE_ID).toOffsetDateTime(); case "yyyy-MM-dd'T'HH:mm:ssZ": return OffsetDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME); default: throw new IllegalArgumentException("Unknown date format ID: " + format); } }
@Override public OffsetTime fromNonNullValue(Timestamp value) { ZoneId currentJavaZone = javaZone == null ? getDefaultZoneId() : javaZone; ZonedDateTime zonedDateTime = value.toInstant().with(ChronoField.NANO_OF_SECOND, value.getNanos()).atZone(currentJavaZone); OffsetDateTime dateTime = zonedDateTime.toOffsetDateTime(); OffsetTime time = dateTime.toOffsetTime(); return time; }