Package jsonvalues

Class JsInstant

All Implemented Interfaces:
Comparable<JsInstant>, JsValue

public final class JsInstant extends JsPrimitive implements Comparable<JsInstant>
Represents an immutable instant. An instant is not part of the JSON specification. It is serialized into its string representation using the ISO-8601 format. A JsInstant and a JsStr are equal if both represent the same date.

For example:


 Instant a = Instant.now();
 JsStr.of(a.toString()).equals(JsInstant.of(a)) // true
 
  • Field Details

    • prism

      public static final fun.optic.Prism<JsValue,Instant> prism
      Prism between the sum type JsValue and JsInstant.
    • value

      public final Instant value
  • Method Details

    • of

      public static JsInstant of(Instant instant)
      Creates a JsInstant from an Instant.
      Parameters:
      instant - the Instant to create the JsInstant from.
      Returns:
      a JsInstant representing the given Instant.
    • of

      public static JsInstant of(String instant)
      Creates a JsInstant from a string representation of an Instant.
      Parameters:
      instant - the string representation of an Instant to create the JsInstant from.
      Returns:
      a JsInstant representing the parsed Instant.
    • map

      public JsInstant map(Function<Instant,Instant> fn)
      Applies a function to the value of this JsInstant.
      Parameters:
      fn - the function to apply.
      Returns:
      a new JsInstant with the result of applying the function to the value.
    • toJsPrimitive

      public JsPrimitive toJsPrimitive()
      Description copied from interface: JsValue
      Returns this JsValue as a JsPrimitive.
      Specified by:
      toJsPrimitive in interface JsValue
      Returns:
      This JsValue as a JsPrimitive.
    • isInstant

      public boolean isInstant()
      Description copied from interface: JsValue
      Returns true if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
      Specified by:
      isInstant in interface JsValue
      Returns:
      True if this JsValue is a JsInstant or a JsString with a value that is a date formatted in ISO-8601.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public int compareTo(JsInstant o)
      Specified by:
      compareTo in interface Comparable<JsInstant>