private static void appendEra(StringBuilder sb, LocalDate localDate) { if (localDate.get(ChronoField.ERA) == IsoEra.BCE.getValue()) { sb.append(" BC"); } } //JCP! endif
/** * Parse a string and return a LocalDateTime representing its value. * * @param s The ISO formated date string to parse. * @return null if s is null or a LocalDateTime of the parsed string s. * @throws SQLException if there is a problem parsing s. */ public LocalDateTime toLocalDateTime(String s) throws SQLException { if (s == null) { return null; } int slen = s.length(); // convert postgres's infinity values to internal infinity magic value if (slen == 8 && s.equals("infinity")) { return LocalDateTime.MAX; } if (slen == 9 && s.equals("-infinity")) { return LocalDateTime.MIN; } ParsedTimestamp ts = parseBackendTimestamp(s); // intentionally ignore time zone // 2004-10-19 10:23:54+03:00 is 2004-10-19 10:23:54 locally LocalDateTime result = LocalDateTime.of(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.nanos); if (ts.era == GregorianCalendar.BC) { return result.with(ChronoField.ERA, IsoEra.BCE.getValue()); } else { return result; } } //JCP! endif
@Override public String format(Temporal temporal) { if (temporal.get(ChronoField.ERA) != IsoEra.CE.getValue()) { return FMT_ERA.format(temporal); } return FMT.format(temporal); }
@Override public String format(Temporal value) { if (value.get(ChronoField.ERA) != IsoEra.CE.getValue()) { return FMT_ERA.format(value); } return FMT.format(value); }
@Override public Temporal adjustInto(Temporal temporal) { return temporal.with(ERA, getValue()); }
@Override public long getLong(TemporalField field) { if (field == ERA) { return getValue(); } else if (field instanceof ChronoField) { throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
@Override public int get(TemporalField field) { if (field == ERA) { return getValue(); } return range(field).checkValidIntValue(getLong(field), field); }