public static FlexiDateTime fromFudgeMsg(
     final FudgeDeserializer deserializer, final FudgeMsg msg) {
   if (msg == null) {
     return null;
   }
   final ZoneId zone = msg.getValue(ZoneId.class, ZONE_FIELD_NAME);
   final Object obj = msg.getValue(DATETIME_FIELD_NAME);
   if (obj instanceof FudgeDateTime) {
     FudgeDateTime fudge = (FudgeDateTime) obj;
     if (fudge.getTime().hasTimezoneOffset()) {
       OffsetDateTime odt = fudge.toOffsetDateTime();
       if (zone != null) {
         return FlexiDateTime.of(odt.atZoneSameInstant(zone));
       }
       return FlexiDateTime.of(odt);
     } else {
       return FlexiDateTime.of(fudge.toLocalDateTime());
     }
   } else if (obj instanceof FudgeDate) {
     FudgeDate fudge = (FudgeDate) obj;
     return FlexiDateTime.of(fudge.toLocalDate());
   } else if (obj instanceof OffsetDateTime) {
     OffsetDateTime odt = (OffsetDateTime) obj;
     if (zone != null) {
       return FlexiDateTime.of(odt.atZoneSameInstant(zone));
     }
     return FlexiDateTime.of(odt);
   } else if (obj instanceof LocalDateTime) {
     return FlexiDateTime.of((LocalDateTime) obj);
   } else if (obj instanceof LocalDate) {
     return FlexiDateTime.of((LocalDate) obj);
   } else {
     throw new IllegalStateException("Fudge message did not contain a valid date-time");
   }
 }
Пример #2
0
 /**
  * Get a LocalDate field (converted from a String internally). Throws a QuandlRuntimeException if
  * it cannot find the field
  *
  * @param fieldName the name of the field
  * @return the field value, or null if the field is null
  */
 public OffsetDateTime getOffsetDateTime(final String fieldName) {
   try {
     if (_jsonObject.isNull(fieldName)) {
       return null;
     } else {
       return OffsetDateTime.parse(_jsonObject.getString(fieldName), DATE_TIME_FORMATTER);
     }
   } catch (JSONException ex) {
     throw new QuandlRuntimeException("Cannot find field", ex);
   }
 }
 @Override
 protected Instant[] testTimes2() {
   Instant one = OffsetDateTime.of(2010, 2, 11, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   Instant two = OffsetDateTime.of(2010, 2, 12, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   Instant three = OffsetDateTime.of(2010, 2, 13, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   Instant four = OffsetDateTime.of(2010, 2, 14, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   Instant five = OffsetDateTime.of(2010, 2, 15, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   Instant six = OffsetDateTime.of(2010, 2, 16, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
   return new Instant[] {one, two, three, four, five, six};
 }