zoneId = ZoneId.from(accessor); } catch (DateTimeException e2) { if (defaultTimeZone == null) {
@Override public String format(TemporalAccessor accessor) { DateTimeZone timeZone = DateUtils.zoneIdToDateTimeZone(ZoneId.from(accessor)); DateTime dateTime = new DateTime(Instant.from(accessor).toEpochMilli(), timeZone); return printer.print(dateTime); }
@Override public ZoneId queryFrom(TemporalAccessor temporal) { return ZoneId.from(temporal); } };
private static ZoneId getAdjust(final String literal) { if (literal.endsWith("Z")) { return ZoneId.from(ZoneOffset.UTC); } else { return ZoneId.systemDefault(); } }
private static ZoneId getAdjust(final String literal) { if (literal.endsWith("Z")) { return ZoneId.from(ZoneOffset.UTC); } else { return ZoneId.systemDefault(); } }
@Override protected Instant parse(String input) throws Exception { if (CharMatcher.DIGIT.matchesAllOf(input)) { // Assume millis, but check for nanos long millis = Long.parseLong(input); if (millis >= 253402300800000L) { // +10000-01-01T00:00:00Z millis = TimeUnit.NANOSECONDS.toMillis(millis); } return Instant.ofEpochMilli(millis); } try { return ZonedDateTime.parse(input).toInstant(); } catch (DateTimeParseException e) { TemporalAccessor ta = RFC_822_FORMAT.parse(input); LocalDateTime dateTime = LocalDateTime.from(ta); return ZonedDateTime.of(dateTime, ta.isSupported(ChronoField.OFFSET_SECONDS) ? ZoneId.from(ta) : ZoneOffset.UTC).toInstant(); } } }
private static Month toMonth(Instant instant) { return instant.atZone(ZoneId.from(ZoneOffset.UTC)).getMonth(); }
/** * Creates a {@link ZonedDateTime} instance based on the given pattern in ISO 8601 format, compatible with the Joda date-time * library. * <p> * Note that there is no direct correspondence between the JODA-style dates and the new JDK 8 date, especially * when it comes to handling milliseconds. * </p> * * @param iso8601 a {@link String} representing a date and/or time pattern, may not be null * @return a {@link ZonedDateTime} instance, never {@code null} * * @throws java.time.format.DateTimeParseException if the given pattern cannot be parsed */ public static ZonedDateTime jodaParse( String iso8601 ) throws DateTimeParseException { CheckArg.isNotNull(iso8601, "iso8601"); TemporalAccessor parse = JODA_ISO8601_FORMATTER.parse(iso8601); LocalDate localDate = LocalDate.from(parse); LocalTime localTime = parse.isSupported(ChronoField.HOUR_OF_DAY) ? LocalTime.from(parse) : LocalTime.MIDNIGHT; ZoneId zoneId = parse.isSupported(ChronoField.OFFSET_SECONDS) ? ZoneId.from(parse) : UTC; return ZonedDateTime.of(localDate, localTime, zoneId); }
ZoneId zone = ZoneId.from( temporal ); ZoneOffset offset = ZoneOffset.from( temporal ); LocalDateTime ldt = LocalDateTime.from( temporal );
/** * Creates a {@link ZonedDateTime} instance based on the given pattern in ISO 8601 format, compatible with the Joda date-time * library. * <p> * Note that there is no direct correspondence between the JODA-style dates and the new JDK 8 date, especially * when it comes to handling milliseconds. * </p> * * @param iso8601 a {@link String} representing a date and/or time pattern, may not be null * @return a {@link ZonedDateTime} instance, never {@code null} * * @throws java.time.format.DateTimeParseException if the given pattern cannot be parsed */ public static ZonedDateTime jodaParse( String iso8601 ) throws DateTimeParseException { CheckArg.isNotNull(iso8601, "iso8601"); TemporalAccessor parse = JODA_ISO8601_FORMATTER.parse(iso8601); LocalDate localDate = LocalDate.from(parse); LocalTime localTime = parse.isSupported(ChronoField.HOUR_OF_DAY) ? LocalTime.from(parse) : LocalTime.MIDNIGHT; ZoneId zoneId = parse.isSupported(ChronoField.OFFSET_SECONDS) ? ZoneId.from(parse) : UTC; return ZonedDateTime.of(localDate, localTime, zoneId); }
ZoneId zone = ZoneId.from( temporal ); ZoneOffset offset = ZoneOffset.from( temporal ); LocalDateTime ldt = LocalDateTime.from( temporal );
/** * Creates a {@link ZonedDateTime} instance based on the given pattern in ISO 8601 format, compatible with the Joda date-time * library. * <p> * Note that there is no direct correspondence between the JODA-style dates and the new JDK 8 date, especially * when it comes to handling milliseconds. * </p> * * @param iso8601 a {@link String} representing a date and/or time pattern, may not be null * @return a {@link ZonedDateTime} instance, never {@code null} * * @throws java.time.format.DateTimeParseException if the given pattern cannot be parsed */ public static ZonedDateTime jodaParse( String iso8601 ) throws DateTimeParseException { CheckArg.isNotNull(iso8601, "iso8601"); TemporalAccessor parse = JODA_ISO8601_FORMATTER.parse(iso8601); LocalDate localDate = LocalDate.from(parse); LocalTime localTime = parse.isSupported(ChronoField.HOUR_OF_DAY) ? LocalTime.from(parse) : LocalTime.MIDNIGHT; ZoneId zoneId = parse.isSupported(ChronoField.OFFSET_SECONDS) ? ZoneId.from(parse) : UTC; return ZonedDateTime.of(localDate, localTime, zoneId); }
ZoneId zone = ZoneId.from(temporal); if (temporal.isSupported(INSTANT_SECONDS)) { try {
zoneId = ZoneId.from(accessor); } catch (DateTimeException e2) { if (defaultTimeZone == null) {
/** * Obtains a zoned date-time in this chronology from another temporal object. * <p> * This creates a date-time in this chronology based on the specified {@code TemporalAccessor}. * <p> * This should obtain a {@code ZoneId} using {@link ZoneId#from(TemporalAccessor)}. * The date-time should be obtained by obtaining an {@code Instant}. * If that fails, the local date-time should be used. * * @param temporal the temporal object to convert, not null * @return the zoned date-time in this chronology, not null * @throws DateTimeException if unable to create the date-time */ @SuppressWarnings({ "rawtypes", "unchecked" }) public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) { try { ZoneId zone = ZoneId.from(temporal); try { Instant instant = Instant.from(temporal); return zonedDateTime(instant, zone); } catch (DateTimeException ex1) { ChronoLocalDateTime cldt = localDateTime(temporal); ChronoLocalDateTimeImpl cldtImpl = ensureChronoLocalDateTime(cldt); return ChronoZonedDateTimeImpl.ofBest(cldtImpl, zone, null); } } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex); } }
public FEELFnResult<TemporalAccessor> invoke(@ParameterName( "date" ) TemporalAccessor date, @ParameterName( "time" ) TemporalAccessor time) { if ( date == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "date", "cannot be null")); } if ( !(date instanceof LocalDate) ) { // FEEL Spec Table 58 "date is a date or date time [...] creates a date time from the given date (ignoring any time component)" [that means ignoring any TZ from `date` parameter, too] // I try to convert `date` to a LocalDate, if the query method returns null would signify conversion is not possible. date = date.query(TemporalQueries.localDate()); if (date == null) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "date", "must be an instance of LocalDate (or must be possible to convert to a FEEL date using built-in date(date) )")); } } if ( time == null ) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "time", "cannot be null")); } if (!(time instanceof LocalTime || (time.query(TemporalQueries.localTime()) != null && time.query(TemporalQueries.zone()) != null))) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "time", "must be an instance of LocalTime or (it must contain localTime AND zone)")); } try { if( date instanceof LocalDate && time instanceof LocalTime ) { return FEELFnResult.ofResult( LocalDateTime.of( (LocalDate) date, (LocalTime) time ) ); } else if (date instanceof LocalDate && (time.query(TemporalQueries.localTime()) != null && time.query(TemporalQueries.zone()) != null)) { return FEELFnResult.ofResult(ZonedDateTime.of((LocalDate) date, LocalTime.from(time), ZoneId.from(time))); } return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "cannot invoke function for the input parameters")); } catch (DateTimeException e) { return FEELFnResult.ofError(new InvalidParametersEvent(Severity.ERROR, "input parameters date-parsing exception", e)); } }