Class ParsedFields

java.lang.Object
io.github.connellite.util.internal.dateparse.ParsedFields

public final class ParsedFields extends Object
Mutable holder for the date-time fields collected by DateTimeScanner and DateTimePatterns.

Ranges are validated by the setters, so the to* methods never throw. A zone or offset is recorded when present but does not shift the wall-clock fields: toLocalDateTime() returns the date-time exactly as written.

  • Constructor Details

    • ParsedFields

      public ParsedFields()
  • Method Details

    • reset

      public void reset()
      Clears all fields so the instance can be reused for another input.
    • setDate

      public boolean setDate(int year, int month, int day)
      Records the calendar date.
      Returns:
      false when the values do not form a real date, leaving the instance unchanged
    • setTime

      public boolean setTime(int hour, int minute, int second, int nano)
      Records the time of day. A second of 60 (leap second) is clamped to 59.

      Based on Jackson: ISO8601Utils.parse (if (seconds > 59 && seconds < 63) seconds = 59).

      Returns:
      false when the values are out of range, leaving the instance unchanged
    • setOffsetSeconds

      public boolean setOffsetSeconds(int offsetSeconds)
      Records a fixed offset from UTC.
      Returns:
      false when offsetSeconds exceeds the ZoneOffset range
    • setZone

      public void setZone(ZoneId zone)
      Records a named zone, and its current offset when no explicit offset was parsed.
    • hasDate

      public boolean hasDate()
    • hasTime

      public boolean hasTime()
    • hasOffset

      public boolean hasOffset()
    • hasZone

      public boolean hasZone()
    • toLocalDate

      public LocalDate toLocalDate()
      Returns:
      the calendar date, or null when the input carried no date
    • toLocalDateTime

      public LocalDateTime toLocalDateTime()
      Returns:
      the date-time, using start of day when the input carried no time, or null when the input carried no date
    • toLocalTime

      public LocalTime toLocalTime()
      Returns:
      the time of day, LocalTime.MIDNIGHT for a date without time, or null when the input carried neither
    • toOffsetDateTime

      public OffsetDateTime toOffsetDateTime()
      Returns:
      the date-time at the parsed offset, falling back to the parsed zone's offset and then to UTC, or null when the input carried no date
    • toOffsetTime

      public OffsetTime toOffsetTime()
      Returns:
      the time of day at the parsed offset or zone, or null when the input carried no time or neither an offset nor a zone
    • toZoneOffset

      public ZoneOffset toZoneOffset()
      Returns:
      the explicit offset written in the input, or null when there was none. A named zone is not turned into an offset.
    • toZoneId

      public ZoneId toZoneId()
      Returns:
      the named zone, or the explicit offset when the input named no zone, or null when it carried neither
    • expandTwoDigitYear

      public static int expandTwoDigitYear(int twoDigitYear, int baseYear)
      Resolves a two-digit year against a sliding window starting 80 years before baseYear, the same pivot SimpleDateFormat uses.

      Based on sqlite-jdbc: FastDateParser.adjustYear.