Package com.oss.asn1

Class AbstractTime

java.lang.Object
com.oss.asn1.AbstractData
com.oss.asn1.AbstractTime
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
GeneralizedTime, UTCTime

public abstract class AbstractTime extends AbstractData
The AbstractTime class is the superclass of the two ASN.1 time types, GeneralizedTime and UTCTime.
Since:
ASN.1/Java 6.0
See Also:
  • Field Summary

    Fields inherited from class com.oss.asn1.AbstractData

    EQUALS, GREATER_THAN, LESS_THAN
  • Method Summary

    Modifier and Type
    Method
    Description
    Clone 'this' object.
    abstract String
    Takes the instance of AbstractTime and converts it to the formatted string, suitable for the encoding.
    final int
    Get the day component of 'this' object.
    final int
    Get the hour component of 'this' object.
    final int
    Get the minutes component of 'this' object.
    final int
    Get the minutes-differential component of 'this' object.
    final int
    Get the month component of 'this' object.
    final int
    Get the seconds component of 'this' object.
    final int
    Get the year component of 'this' object.
    int
    Returns a hash code for this object
    int[]
    Get an int array containing the components of this object.
    abstract AbstractTime
    Takes formatted string that contains the value of time type, splits the string to the components and initializes the instance of the AbstractTime class, passed as a parameter.
    final void
    setDay(int day)
    Set the day component of 'this' object.
    final void
    setHour(int hour)
    Set the hour component of 'this' object.
    final void
    setMinute(int minute)
    Set the minutes component of 'this' object.
    void
    setMinuteDifferential(int minDiff)
    Set the minutes-differential component of 'this' object.
    final void
    setMonth(int month)
    Set the month component of 'this' object.
    final void
    setSecond(int second)
    Set the seconds component of 'this' object.
    final void
    setValue(int[] components)
    Set the value of an AbstractTime object from an array of int that contains the year, month, day, hour, minutes, seconds and minutes-differential.
    final void
    setYear(int year)
    Set the year component of 'this' object.
    final Date
    Get a Java Date object primed with the data from 'this' AbstractTime object.
    toDate(Calendar calendar)
    Get a Java Date object primed with the data from 'this' AbstractTime object using the calendar "calendar".
    boolean
    Does basic sanity checks for the value of time types.

    Methods inherited from class com.oss.asn1.AbstractData

    abstractEqualTo, delete, equals, getTypeName, isEncodable, isPDU, isValid, toString, toString

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • clone

      public AbstractTime clone()
      Clone 'this' object.
      Returns:
      deep copy of 'this' object.
    • getYear

      public final int getYear()
      Get the year component of 'this' object.
      Returns:
      int value indicating the year.
    • getMonth

      public final int getMonth()
      Get the month component of 'this' object.
      Returns:
      int value indicating the month.
    • getDay

      public final int getDay()
      Get the day component of 'this' object.
      Returns:
      int value indicating the day.
    • getHour

      public final int getHour()
      Get the hour component of 'this' object.
      Returns:
      int value indicating the hour.
    • getMinute

      public final int getMinute()
      Get the minutes component of 'this' object.
      Returns:
      int value indicating the minute.
    • getSecond

      public final int getSecond()
      Get the seconds component of 'this' object.
      Returns:
      int value indicating the second.
    • getMinuteDifferential

      public final int getMinuteDifferential()
      Get the minutes-differential component of 'this' object.
      Returns:
      int value indicating the minute-differential.
    • setYear

      public final void setYear(int year)
      Set the year component of 'this' object.
      Parameters:
      year - the year to set.
    • setMonth

      public final void setMonth(int month)
      Set the month component of 'this' object.
      Parameters:
      month - the month to set.
    • setDay

      public final void setDay(int day)
      Set the day component of 'this' object.
      Parameters:
      day - the day to set.
    • setHour

      public final void setHour(int hour)
      Set the hour component of 'this' object.
      Parameters:
      hour - the hour to set.
    • setMinute

      public final void setMinute(int minute)
      Set the minutes component of 'this' object.
      Parameters:
      minute - the minute to set.
    • setSecond

      public final void setSecond(int second)
      Set the seconds component of 'this' object.
      Parameters:
      second - the second to set.
    • setMinuteDifferential

      public void setMinuteDifferential(int minDiff)
      Set the minutes-differential component of 'this' object.
      Parameters:
      minDiff - the minute-differential to set.
    • setValue

      public final void setValue(int[] components)
      Set the value of an AbstractTime object from an array of int that contains the year, month, day, hour, minutes, seconds and minutes-differential.
      Parameters:
      components - an array of time components.
    • intArrayValue

      public int[] intArrayValue()
      Get an int array containing the components of this object. The components are in the order: year, month, day, hour, minutes, seconds, minutes-differential.
      Returns:
      int array of time components.
    • toDate

      public final Date toDate()
      Get a Java Date object primed with the data from 'this' AbstractTime object. Note that the precision stops at seconds, milliseconds are lost.
      Returns:
      reference to the Java Date object set to 'this' object's year, month, day, hour, minutes and seconds.
    • toDate

      public Date toDate(Calendar calendar)
      Get a Java Date object primed with the data from 'this' AbstractTime object using the calendar "calendar". Note that the precision stops at seconds, milliseconds are lost.
      Parameters:
      calendar - the Calendar to use to compute the Date.
      Returns:
      reference to the Java Date set to 'this' object's year, month, day, hour, minutes and seconds by using "calendar".
    • validateTime

      public boolean validateTime() throws com.oss.util.BadTimeValueException
      Does basic sanity checks for the value of time types. Subclasses are supposed to override this method to implement more strict or additional checks. This version of the method checks if:
      1. the month is in range 1..12
      2. the day is in range 1..31
      3. the hour is in range 0..23
      4. the minute is in range 0..59
      5. the second is in range 0..59
      If this is not the case a BadTimeValueException exception is thrown.
      Returns:
      true if value passed validation check
      Throws:
      com.oss.util.BadTimeValueException - if any component has an illegal value.
    • formatTime

      public abstract String formatTime() throws com.oss.util.BadTimeValueException
      Takes the instance of AbstractTime and converts it to the formatted string, suitable for the encoding. Specific subclasses must implement this method.
      Returns:
      string that contain the value, formatted accordingly to the specific time type
      Throws:
      com.oss.util.BadTimeValueException - if the the value contains invalid components that make the formatting impossible
    • parseTime

      public abstract AbstractTime parseTime(String str) throws BadTimeFormatException
      Takes formatted string that contains the value of time type, splits the string to the components and initializes the instance of the AbstractTime class, passed as a parameter. If the string has invalid format, a BadTimeFormatException exception is thrown. Specific subclasses must implement this method.
      Parameters:
      str - formatted string that contains the value of time type
      Returns:
      reference to initialized object
      Throws:
      BadTimeFormatException - if str has invalid format
    • hashCode

      public int hashCode()
      Returns a hash code for this object
      Overrides:
      hashCode in class AbstractData
      Returns:
      a hash code for this object