public static void toFudgeMsg( final FudgeSerializer serializer, final FlexiDateTime object, final MutableFudgeMsg msg) { Temporal best = object.toBest(); best = (best instanceof ZonedDateTime ? ((ZonedDateTime) best).toOffsetDateTime() : best); addToMessage(msg, DATETIME_FIELD_NAME, best); ZoneId zone = object.getZone(); if (zone != null && zone instanceof ZoneOffset == false) { addToMessage(msg, ZONE_FIELD_NAME, zone); } }
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"); } }