Package com.isode.som
Class SomUtcTime
java.lang.Object
com.isode.som.SomUtcTime
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new object representing the current date/time in the local timezone.SomUtcTime(int seconds) Create a new SomUtcTime, setting it from a seconds valueSomUtcTime(String utcstring) Deprecated.SomUtcTime(String utcstring, SomUtcTime.TimeStringType type) Create a new SomUtcTime object, setting its values from the utc or generalized time string passed inSomUtcTime(Date date) Create a new object representing a specific date/time in the local timezone. -
Method Summary
Modifier and TypeMethodDescriptiongetDate()Return a Java Date object representing the UTCtime.static SomUtcTimeFactory method to return an "empty" UTCtime.getOffsetTime(Integer offset) Return SomUtcTime object with value shifted by given offsetvoidincrement(int seconds) Increment the value of a SomUtcTime object by a number of secondsbooleanisEmpty()Determine whether this object represents an empty date.static voidMain method for unit testing this class.offsetFrom(Date date) Get a string indicating the days, hours, miunutes and seconds offset for this SomUtcTime value from a specified DatelongoffsetMilliSecondsFrom(Date date) Get a seconds offset for this SomUtcTime value from a specified DateoffsetMinutesFrom(Date date) Get a minutes offset for this SomUtcTime value from a specified DateoffsetSecondsFrom(Date date) Get a seconds offset for this SomUtcTime value from a specified DatetoString()Make printable version of the UTCtime.Make UTC string version of the UTCtime.Make UTC string version of the UTCtime.
-
Constructor Details
-
SomUtcTime
Create a new object representing a specific date/time in the local timezone.- Parameters:
date- the time/date to use
-
SomUtcTime
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 parsetype- 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
Get a seconds offset for this SomUtcTime value from a specified Date- Parameters:
date- Date to get difference from- Returns:
- Difference in seconds
-
offsetMilliSecondsFrom
Get a seconds offset for this SomUtcTime value from a specified Date- Parameters:
date- Date to get difference from- Returns:
- Difference in milliseconds
-
offsetMinutesFrom
Get a minutes offset for this SomUtcTime value from a specified Date- Parameters:
date- Date to get difference from- Returns:
- Difference in minutes
-
offsetFrom
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
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 togetDate()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
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
Return SomUtcTime object with value shifted by given offset- Parameters:
offset- in seconds used for shifting- Returns:
- a new SomUtcTime object
-
toString
Make printable version of the UTCtime. This will never be null. -
toUtcString
Make UTC string version of the UTCtime. This will never be null.- Returns:
- UTC time string
-
toUtcString
Make UTC string version of the UTCtime. This will never be null.- Parameters:
type- time string type to return- Returns:
- UTC time string
-
main
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
-