/** * {@inheritDoc} */ @Override protected OffsetDateTime parse(String offsetDateTimeAsString) { return OffsetDateTime.parse(offsetDateTimeAsString); }
private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) { OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length]; for (int i = 0; i < dateTimesAsString.length; i++) { dates[i] = OffsetDateTime.parse(dateTimesAsString[i]); } return dates; }
private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) { OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length]; for (int i = 0; i < dateTimesAsString.length; i++) { dates[i] = OffsetDateTime.parse(dateTimesAsString[i]); } return dates; }
/** * {@inheritDoc} */ @Override protected OffsetDateTime parse(String offsetDateTimeAsString) { return OffsetDateTime.parse(offsetDateTimeAsString); }
@Override protected OffsetDateTime parse(@Nullable final String input) throws Exception { return OffsetDateTime.parse(input); } }
/** * Maps {@code stringValue} to {@code OffsetDateTime}. * * @param stringValue source value as a {@code String} * @return mapped {@code stringValue} to {@code OffsetDateTime} * @see OffsetDateTime#parse(CharSequence) */ public static OffsetDateTime toOffsetDateTime(String stringValue) { return OffsetDateTime.parse(stringValue); }
@Override public OffsetDateTime parse(String text, Locale locale) throws ParseException { return OffsetDateTime.parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME); }
@Override protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { try { return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } catch (DateTimeException e) { return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key); } } }
@Nullable private static Instant getInstant(Object o) { try { if (o instanceof String) { return OffsetDateTime.parse((String) o, TIMESTAMP_PATTERN).toInstant(); } else if (o instanceof Long) { return Instant.ofEpochMilli((Long) o); } } catch (DateTimeException | ClassCastException e) { return null; } return null; } }
/** * @param s string in format {@link #DATETIME_FORMAT} * @throws SonarException when string cannot be parsed * @since 6.6 */ public static OffsetDateTime parseOffsetDateTime(String s) { try { return OffsetDateTime.parse(s, DATETIME_FORMATTER); } catch (DateTimeParseException e) { throw MessageException.of("The date '" + s + "' does not respect format '" + DATETIME_FORMAT + "'", e); } }
@Override public TemporalAccessor parse(String text, Locale locale) throws ParseException { DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale); if (LocalDate.class == this.temporalAccessorType) { return LocalDate.parse(text, formatterToUse); } else if (LocalTime.class == this.temporalAccessorType) { return LocalTime.parse(text, formatterToUse); } else if (LocalDateTime.class == this.temporalAccessorType) { return LocalDateTime.parse(text, formatterToUse); } else if (ZonedDateTime.class == this.temporalAccessorType) { return ZonedDateTime.parse(text, formatterToUse); } else if (OffsetDateTime.class == this.temporalAccessorType) { return OffsetDateTime.parse(text, formatterToUse); } else if (OffsetTime.class == this.temporalAccessorType) { return OffsetTime.parse(text, formatterToUse); } else { throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType); } }
@Override protected OffsetDateTime deserialize(String key, DeserializationContext ctxt) throws IOException { try { return OffsetDateTime.parse(key, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } catch (DateTimeException e) { return _handleDateTimeException(ctxt, OffsetDateTime.class, e, key); } } }
public static long parseDateTime(String dateTimeStr) { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); return dateTime.toInstant().toEpochMilli(); }
public static Date toDate(String dateString) { try { return dateParserNoMillis().parse(dateString); } catch (ParseException e) { OffsetDateTime offsetDateTime = OffsetDateTime.parse(dateString); return new Date(offsetDateTime.toInstant().toEpochMilli()); } }
@Override public TemporalAccessor parse(String text, Locale locale) throws ParseException { DateTimeFormatter formatterToUse = DateTimeContextHolder.getFormatter(this.formatter, locale); if (LocalDate.class == this.temporalAccessorType) { return LocalDate.parse(text, formatterToUse); } else if (LocalTime.class == this.temporalAccessorType) { return LocalTime.parse(text, formatterToUse); } else if (LocalDateTime.class == this.temporalAccessorType) { return LocalDateTime.parse(text, formatterToUse); } else if (ZonedDateTime.class == this.temporalAccessorType) { return ZonedDateTime.parse(text, formatterToUse); } else if (OffsetDateTime.class == this.temporalAccessorType) { return OffsetDateTime.parse(text, formatterToUse); } else if (OffsetTime.class == this.temporalAccessorType) { return OffsetTime.parse(text, formatterToUse); } else { throw new IllegalStateException("Unsupported TemporalAccessor type: " + this.temporalAccessorType); } }
public static long parseDateAsDuration(String dateTimeStr) { try { OffsetDateTime dateTime = OffsetDateTime.parse(dateTimeStr, DateTimeFormatter.ISO_DATE_TIME); Duration duration = Duration.between(OffsetDateTime.now(), dateTime); return duration.toMillis(); } catch (Exception e) { return TimeUtils.parseTimeString(dateTimeStr); } }
@Override public Object fromString(final String str) { try { return OffsetDateTime.parse(str); } catch (final DateTimeParseException e) { final ConversionException exception = new ConversionException("Cannot parse value as offset date time", e); exception.add("value", str); throw exception; } }
private static CalendarEventModel.CalendarEventTime getEventTime(EventDateTime dateTime) { if (dateTime == null) { return null; } OffsetDateTime offsetDateTime; if (dateTime.getDate() == null) { offsetDateTime = OffsetDateTime.parse(dateTime.getDateTime().toString()); } else { offsetDateTime = OffsetDateTime.from( LocalDate.parse(dateTime.getDate().toString()).atStartOfDay(ZoneId.of("UTC"))); } return new CalendarEventModel.CalendarEventTime(offsetDateTime, dateTime.getDate() != null); }
OffsetDateTime offsetDateTime = OffsetDateTime.parse(text);
@Override public void logBeforeExecution(StatementContext ctx) { String toString = ctx.getBinding() .findForName(name, ctx) .orElseThrow(AssertionError::new) .toString(); insertedTimestamp = OffsetDateTime.parse(toString); insertedSqlTimestamp = Timestamp.from(insertedTimestamp.toInstant()); }