Package org.pkl.core

Class Duration

java.lang.Object
org.pkl.core.Duration
All Implemented Interfaces:
Serializable, Value

public final class Duration extends Object implements Value
Java representation of a pkl.base#Duration value.
See Also:
  • Constructor Details

    • Duration

      public Duration(double value, DurationUnit unit)
      Constructs a new duration with the given value and unit.
  • Method Details

    • ofNanos

      public static Duration ofNanos(double value)
      Constructs a new duration with the given value and unit DurationUnit.NANOS.
    • ofMicros

      public static Duration ofMicros(double value)
      Constructs a new duration with the given value and unit DurationUnit.MICROS.
    • ofMillis

      public static Duration ofMillis(double value)
      Constructs a new duration with the given value and unit DurationUnit.MILLIS.
    • ofSeconds

      public static Duration ofSeconds(double value)
      Constructs a new duration with the given value and unit DurationUnit.SECONDS.
    • ofMinutes

      public static Duration ofMinutes(double value)
      Constructs a new duration with the given value and unit DurationUnit.MINUTES.
    • ofHours

      public static Duration ofHours(double value)
      Constructs a new duration with the given value and unit DurationUnit.HOURS.
    • ofDays

      public static Duration ofDays(double value)
      Constructs a new duration with the given value and unit DurationUnit.DAYS.
    • getValue

      public double getValue()
      Returns the value of this duration. The value is relative to the unit and may be negative.
    • toIsoString

      public String toIsoString()
      Returns an ISO 8601 representation of this duration.
    • getUnit

      public DurationUnit getUnit()
      Returns the unit of this duration.
    • inNanos

      public double inNanos()
      Returns the value of this duration measured in DurationUnit.NANOS.
    • inMicros

      public double inMicros()
      Returns the value of this duration measured in DurationUnit.MICROS.
    • inMillis

      public double inMillis()
      Returns the value of this duration measured in DurationUnit.MILLIS.
    • inSeconds

      public double inSeconds()
      Returns the value of this duration measured in DurationUnit.SECONDS.
    • inMinutes

      public double inMinutes()
      Returns the value of this duration measured in DurationUnit.MINUTES.
    • inHours

      public double inHours()
      Returns the value of this duration measured in DurationUnit.HOURS.
    • inDays

      public double inDays()
      Returns the value of this duration measured in DurationUnit.DAYS.
    • inWholeNanos

      public long inWholeNanos()
      Returns the value of this duration measured in whole DurationUnit.NANOS.
    • inWholeMicros

      public long inWholeMicros()
      Returns the value of this duration measured in whole DurationUnit.MICROS.
    • inWholeMillis

      public long inWholeMillis()
      Returns the value of this duration measured in whole DurationUnit.MILLIS.
    • inWholeSeconds

      public long inWholeSeconds()
      Returns the value of this duration measured in whole DurationUnit.SECONDS.
    • inWholeMinutes

      public long inWholeMinutes()
      Returns the value of this duration measured in whole DurationUnit.MINUTES.
    • inWholeHours

      public long inWholeHours()
      Returns the value of this duration measured in whole DurationUnit.HOURS.
    • inWholeDays

      public long inWholeDays()
      Returns the value of this duration measured in whole DurationUnit.DAYS.
    • toJavaDuration

      public Duration toJavaDuration()
      Converts this duration to a Duration. If getValue() is NaN, +/-Infinity or too large to fit into Duration, ArithmeticException is thrown.
    • convertTo

      public Duration convertTo(DurationUnit other)
      Returns a new duration with the given unit and this value converted to the given unit.
    • convertValueTo

      public double convertValueTo(DurationUnit other)
      Returns the value of this duration converted to the given unit.
    • accept

      public void accept(ValueVisitor visitor)
      Invokes the given visitor's visit method for this Value.
      Specified by:
      accept in interface Value
    • accept

      public <T> T accept(ValueConverter<T> converter)
      Invokes the given converters's convert method for this Value.
      Specified by:
      accept in interface Value
    • getClassInfo

      public PClassInfo<?> getClassInfo()
      Returns information about the Pkl class associated with this Value.
      Specified by:
      getClassInfo in interface Value
    • equals

      public boolean equals(@Nullable @Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object