Class Timestamp

java.lang.Object
org.scictrl.csshell.Timestamp
All Implemented Interfaces:
Comparable<Timestamp>

public final class Timestamp extends Object implements Comparable<Timestamp>
This is timestamp object with nanosecond resolution. It holds two long values. One is with millisoecnd resolution and represents Java standart UTC format. Second long value is with nanosecond resolution and its absolute value is lower than 1ms or 1000000ns.
Author:
igor@scictrl.com
  • Constructor Details

    • Timestamp

      public Timestamp()
      Default constructor, uses system time for initialization.
    • Timestamp

      public Timestamp(long milli, long nano)
      Creates timestamp representing provided values. If nanoseconds exceed 1000000 or -1000000 then they are truncated to nanoseconds within millisecond and millisecond is corrected.
      Parameters:
      milli - a long
      nano - a long
  • Method Details

    • getMilliseconds

      public long getMilliseconds()
      Returns time in milliseconds since epoch (standard Java UTC time, as returned by System.currentTimeMillis())
      Returns:
      Returns the milliseconds.
    • getNanoseconds

      public long getNanoseconds()

      Getter for the field nanoseconds.

      Returns:
      Returns the nanoseconds within the millisecond.
    • compareTo

      public int compareTo(Timestamp o)

      compareTo.

      Specified by:
      compareTo in interface Comparable<Timestamp>
      Parameters:
      o - a Timestamp object
      Returns:
      a int
    • toNanoTime

      public long toNanoTime()
      Returns time in nanoseconds since epoch. Not that this in only usefull for calculating time difference for up to 292 years (263 nanoseconds) since this is maximum time possible in nanoseconds due to long value range overflow.
      Returns:
      up to approx. 292 years big nano time
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

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

      public String toString(Timestamp.Format format)

      toString.

      Parameters:
      format - a Timestamp.Format object
      Returns:
      Returns timestamp as string formated as specified.
    • getSeconds

      public long getSeconds()
      Get seconds since epoch, i.e. 1 January 1970 0:00 UTC.
      Returns:
      a long
    • toDouble

      public double toDouble()
      Converts timestamp to double.
      Returns:
      a double
    • isValid

      public boolean isValid()

      isValid.

      Returns:
      Returns true if time fields > 0.
    • isGreaterThan

      public boolean isGreaterThan(Timestamp other)

      isGreaterThan.

      Parameters:
      other - Other time stamp
      Returns:
      Returns true if this time stamp is greater than the other time stamp.
    • isGreaterOrEqual

      public boolean isGreaterOrEqual(Timestamp other)

      isGreaterOrEqual.

      Parameters:
      other - Other time stamp
      Returns:
      Returns true if this time stamp is greater than or equal to the other time stamp.
    • isLessThan

      public boolean isLessThan(Timestamp other)

      isLessThan.

      Parameters:
      other - Other time stamp
      Returns:
      Returns true if this time stamp is less than the other time stamp.
    • isLessOrEqual

      public boolean isLessOrEqual(Timestamp other)

      isLessOrEqual.

      Parameters:
      other - Other time stamp
      Returns:
      Returns true if this time stamp is less than or equal to the other time stamp.