Package org.pkl.core

Class Duration

  • All Implemented Interfaces:
    java.io.Serializable, Value

    public final class Duration
    extends java.lang.Object
    implements Value
    Java representation of a pkl.base#Duration value.
    See Also:
    Serialized Form
    • Constructor Detail

      • Duration

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

      • 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 java.lang.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 java.time.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 java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object