Class StringConverter

java.lang.Object
org.joda.time.convert.AbstractConverter
org.joda.time.convert.StringConverter
All Implemented Interfaces:
Converter, DurationConverter, InstantConverter, IntervalConverter, PartialConverter, PeriodConverter

StringConverter converts from a String to an instant, partial, duration, period or interval..
Since:
1.0
  • Field Details

  • Constructor Details

    • StringConverter

      protected StringConverter()
      Restricted constructor.
  • Method Details

    • getInstantMillis

      public long getInstantMillis(Object object, Chronology chrono)
      Gets the millis, which is the ISO parsed string value.
      Specified by:
      getInstantMillis in interface InstantConverter
      Overrides:
      getInstantMillis in class AbstractConverter
      Parameters:
      object - the String to convert, must not be null
      chrono - the chronology to use, non-null result of getChronology
      Returns:
      the millisecond value
      Throws:
      IllegalArgumentException - if the value if invalid
    • getPartialValues

      public int[] getPartialValues(ReadablePartial fieldSource, Object object, Chronology chrono, DateTimeFormatter parser)
      Extracts the values of the partial from an object of this converter's type. This method checks if the parser has a zone, and uses it if present. This is most useful for parsing local times with UTC.
      Specified by:
      getPartialValues in interface PartialConverter
      Overrides:
      getPartialValues in class AbstractConverter
      Parameters:
      fieldSource - a partial that provides access to the fields. This partial may be incomplete and only getFieldType(int) should be used
      object - the object to convert
      chrono - the chronology to use, which is the non-null result of getChronology()
      parser - the parser to use, may be null
      Returns:
      the array of field values that match the fieldSource, must be non-null valid
      Throws:
      ClassCastException - if the object is invalid
      IllegalArgumentException - if the value if invalid
      Since:
      1.3
    • getDurationMillis

      public long getDurationMillis(Object object)
      Gets the duration of the string using the standard type. This matches the toString() method of ReadableDuration.
      Specified by:
      getDurationMillis in interface DurationConverter
      Parameters:
      object - the String to convert, must not be null
      Returns:
      the millisecond duration
      Throws:
      ClassCastException - if the object is invalid
    • setInto

      public void setInto(ReadWritablePeriod period, Object object, Chronology chrono)
      Extracts duration values from an object of this converter's type, and sets them into the given ReadWritableDuration.
      Specified by:
      setInto in interface PeriodConverter
      Parameters:
      period - period to get modified
      object - the String to convert, must not be null
      chrono - the chronology to use
      Throws:
      ClassCastException - if the object is invalid
    • setInto

      public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono)
      Sets the value of the mutable interval from the string.
      Specified by:
      setInto in interface IntervalConverter
      Parameters:
      writableInterval - the interval to set
      object - the String to convert, must not be null
      chrono - the chronology to use, may be null
    • getSupportedType

      public Class<?> getSupportedType()
      Returns String.class.
      Specified by:
      getSupportedType in interface Converter
      Returns:
      String.class