コード例 #1
0
ファイル: LocalDateParser.java プロジェクト: ycmag/jooby
 private static LocalDate parse(final DateTimeFormatter formatter, final String value) {
   try {
     Instant epoch = Instant.ofEpochMilli(Long.parseLong(value));
     ZonedDateTime zonedDate =
         epoch.atZone(Optional.ofNullable(formatter.getZone()).orElse(ZoneId.systemDefault()));
     return zonedDate.toLocalDate();
   } catch (NumberFormatException ex) {
     return LocalDate.parse(value, formatter);
   }
 }
コード例 #2
0
  public static DateTimeFormatter getDateTimeFormatter(ColumnDefinition<?, ?> columnDefinition) {
    DateTimeFormatter dtf;

    if (columnDefinition.has(JavaDateTimeFormatterProperty.class)) {
      dtf = columnDefinition.lookFor(JavaDateTimeFormatterProperty.class).getFormatter();
    } else if (columnDefinition.has(DateFormatProperty.class)) {
      dtf =
          DateTimeFormatter.ofPattern(
              columnDefinition.lookFor(DateFormatProperty.class).getPattern());
    } else {
      throw new IllegalArgumentException("No date format pattern specified");
    }

    final ZoneId zoneId = _getZoneId(columnDefinition);

    if (zoneId != null) {
      dtf = dtf.withZone(zoneId);
    } else if (dtf.getZone() == null) {
      dtf = dtf.withZone(ZoneId.systemDefault());
    }

    return dtf;
  }