Package com.isode.som

Class SomUtcTime

java.lang.Object
com.isode.som.SomUtcTime

public class SomUtcTime extends Object
This class provides a way to encapsulate a UTCtime struct as used by dcapi to represent time values returned by the DSA. When converting to a Date object, the value will represent a time in the user's current timezone. For example, a UTCtime value of 11am will produce a date with a time of 6am if the current timezone is America/New_York.
  • Constructor Details

    • SomUtcTime

      public SomUtcTime(Date date)
      Create a new object representing a specific date/time in the local timezone.
      Parameters:
      date - the time/date to use
    • SomUtcTime

      public SomUtcTime(String utcstring)
      Deprecated.
      Create a new SomUtcTime object, setting its values from the time string passed in. This is a compatibility interface which attempts to guess whether the string is UTC or Generalized by inspection. This is not infallible!
      Parameters:
      utcstring - time string to parse
    • SomUtcTime

      public SomUtcTime(String utcstring, SomUtcTime.TimeStringType type) throws SomInvalidTimeStringException
      Create a new SomUtcTime object, setting its values from the utc or generalized time string passed in
      Parameters:
      utcstring - time string to parse
      type - indicates if is UTCTime or Generalized
      Throws:
      SomInvalidTimeStringException - if the time string is invalid
    • SomUtcTime

      public SomUtcTime(int seconds)
      Create a new SomUtcTime, setting it from a seconds value
      Parameters:
      seconds - value for use in initialization
    • SomUtcTime

      public SomUtcTime()
      Create a new object representing the current date/time in the local timezone.
  • Method Details

    • offsetSecondsFrom

      public Integer offsetSecondsFrom(Date date)
      Get a seconds offset for this SomUtcTime value from a specified Date
      Parameters:
      date - Date to get difference from
      Returns:
      Difference in seconds
    • offsetMilliSecondsFrom

      public long offsetMilliSecondsFrom(Date date)
      Get a seconds offset for this SomUtcTime value from a specified Date
      Parameters:
      date - Date to get difference from
      Returns:
      Difference in milliseconds
    • offsetMinutesFrom

      public Integer offsetMinutesFrom(Date date)
      Get a minutes offset for this SomUtcTime value from a specified Date
      Parameters:
      date - Date to get difference from
      Returns:
      Difference in minutes
    • offsetFrom

      public String offsetFrom(Date date)
      Get a string indicating the days, hours, miunutes and seconds offset for this SomUtcTime value from a specified Date
      Parameters:
      date - Date to get difference from
      Returns:
      String indicating difference
    • increment

      public void increment(int seconds)
      Increment the value of a SomUtcTime object by a number of seconds
      Parameters:
      seconds - number to increment by
    • getEmptyUTCtime

      public static SomUtcTime getEmptyUTCtime()
      Factory method to return an "empty" UTCtime. This method provides an object suitable to be passed to the JNI layer to be filled in. A call to getDate() on an "empty" UTCtime object will return null.
      Returns:
      an empty UTCtime object
    • isEmpty

      public boolean isEmpty()
      Determine whether this object represents an empty date. An empty UTCtime is one that represents a time field from the DSA which has not been initialised (for example, the last update time of an agreement which has never been updated).
      Returns:
      true if this is an empty date, false otherwise.
    • getDate

      public Date getDate()
      Return a Java Date object representing the UTCtime.
      Returns:
      the time as a java.util.Date object. For an "empty" UTCtime, a null value will be returned.
    • getOffsetTime

      public SomUtcTime getOffsetTime(Integer offset)
      Return SomUtcTime object with value shifted by given offset
      Parameters:
      offset - in seconds used for shifting
      Returns:
      a new SomUtcTime object
    • toString

      public String toString()
      Make printable version of the UTCtime. This will never be null.
      Overrides:
      toString in class Object
      Returns:
      a date/time string, or "" for an empty object.
    • toUtcString

      public String toUtcString()
      Make UTC string version of the UTCtime. This will never be null.
      Returns:
      UTC time string
    • toUtcString

      public String toUtcString(SomUtcTime.TimeStringType type)
      Make UTC string version of the UTCtime. This will never be null.
      Parameters:
      type - time string type to return
      Returns:
      UTC time string
    • main

      public static void main(String[] args)
      Main method for unit testing this class. The main method constructs a new UTCtime for the current date/time, then turns it into a Date and back into a UTCtime, displaying the results of conversion, which should all be the same, regardless of the current timezone. You can test the class in different timezones by using, e.g.
         java com.isode.dconsole.UTCtime    (current timezone)
         java -Duser.timezone=America/New_York com.isode.dconsole.UTCtime
         java -Duser.timezone=Australia/Broken_Hill com.isode.dconsole.UTCtime
       
      See www.worldtimeserver.com to confirm the results
      Parameters:
      args - notused