pasn.misc
Class ASN1TimeValue

java.lang.Object
  extended by pasn.misc.ASN1TimeValue

public final class ASN1TimeValue
extends java.lang.Object

Simplifies time assignment to ASN.1 time objects.

Please refer to ASN1UTCTime or ASN1GeneralizedTime for time formats signfication

Author:
N. Cottin - http://www.ncottin.net

Field Summary
static int DAY
           
static java.lang.String DEFAULT_TIMEZONE
          Default timezone value, set to GMT+0000
static int HOUR
           
static int MILLISECOND
           
static int MINUTE
           
static int MONTH
           
static int SECOND
           
static int YEAR
           
 
Constructor Summary
ASN1TimeValue(boolean shortYear)
           Creates a non-initialized time value.
 
Method Summary
 ASN1TimeValue duplicate()
          Creates a copy of this time value
 boolean equals(java.lang.Object obj)
           
 int getDay()
           
 int getField(int timeField)
          Retrieves a particular time field.
 int getHour()
           
 int getMillisecond()
           
 int getMinute()
           
 int getMonth()
           
 int getSecond()
           
 ASN1TimeFormat getTimeFormat()
          Returns the printing (or encoding) format of this TIME object
 java.lang.String getTimeZone()
          Returns the current time zone identifier
 java.util.Calendar getValue()
          Returns the date value enclosed within this time object
 int getYear()
           
 boolean isInitialized()
          Indicates whether this time object is initialized with a time value or not
 boolean isShortYear()
           
 boolean isValid()
           
static boolean isValid(int year, int month, int day, int hour, int minute, int second, int milli, java.util.TimeZone tz)
           
 void reset()
           Disables time fields values so that isInitialized() returns false.
 void setMillisecond(int milli)
          Initializes the millisecond field.
 void setTimeFormat(ASN1TimeFormat tf)
          Sets the format for printing or encoding among the proposed formats of this TIME object
 void setTimeZone()
          Sets the current timezone to DEFAULT_TIMEZONE
 void setTimeZone(java.lang.String zone)
          Sets the time deviation around GMT to create accurate times by differencing time zones
 void setValue()
          Sets this time with the current date and time values
 void setValue(java.util.Calendar value)
          Sets the internal time with the given calendar
 void setValue(java.util.Date value)
          Sets this time with the given date and time values
 void setValues(int year, int month, int day, int hour, int minute, int second)
          Initializes all the internal time fields but milliseconds.
 java.lang.String toString()
           
 java.lang.String toString(ASN1TimeFormat format, boolean shortYear)
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

YEAR

public static final int YEAR
See Also:
Constant Field Values

MONTH

public static final int MONTH
See Also:
Constant Field Values

DAY

public static final int DAY
See Also:
Constant Field Values

HOUR

public static final int HOUR
See Also:
Constant Field Values

MINUTE

public static final int MINUTE
See Also:
Constant Field Values

SECOND

public static final int SECOND
See Also:
Constant Field Values

MILLISECOND

public static final int MILLISECOND
See Also:
Constant Field Values

DEFAULT_TIMEZONE

public static final java.lang.String DEFAULT_TIMEZONE
Default timezone value, set to GMT+0000

See Also:
Constant Field Values
Constructor Detail

ASN1TimeValue

public ASN1TimeValue(boolean shortYear)

Creates a non-initialized time value.

Timezone is set to DEFAULT_TIMEZONE

Parameters:
shortYear - True means 2-digits year and false 4-digits year
See Also:
setValue()
Method Detail

isValid

public boolean isValid()

isValid

public static boolean isValid(int year,
                              int month,
                              int day,
                              int hour,
                              int minute,
                              int second,
                              int milli,
                              java.util.TimeZone tz)

isShortYear

public boolean isShortYear()

setValue

public void setValue()
Sets this time with the current date and time values


setValue

public void setValue(java.util.Date value)
Sets this time with the given date and time values

Parameters:
value - The date to initialize this time object with. A null date value represents the current time value and is strictly equivalent to setValue()

setValue

public void setValue(java.util.Calendar value)
Sets the internal time with the given calendar

Parameters:
value - The date to initialize this time object with. A null value represents the current time value and is strictly equivalent to setValue()

setTimeZone

public void setTimeZone()
Sets the current timezone to DEFAULT_TIMEZONE

See Also:
setTimeZone(String)

setTimeZone

public void setTimeZone(java.lang.String zone)
Sets the time deviation around GMT to create accurate times by differencing time zones

Parameters:
zone - A stringified time zone, such as "GMT+01:00". The general syntax is GMT[+|-]hh[[:]mm]. DEFAULT_TIMEZONE is used in case the given timezone ID is not valid according to the general syntax and accepted hh and mm values

setValues

public void setValues(int year,
                      int month,
                      int day,
                      int hour,
                      int minute,
                      int second)
Initializes all the internal time fields but milliseconds. The validity of these values is not verified

Parameters:
year - Year value (such as 2005)
month - Month index, given by any value of MONTH
day - Day index, which corresponds to DAY
hour - Hour of the day, which corresponds to HOUR
minute - Minutes within the current hour, which corresponds to MINUTE
second - Seconds within the current minute, which corresponds to SECOND
See Also:
setMillisecond(int)

setMillisecond

public void setMillisecond(int milli)
Initializes the millisecond field. The validity of this field is not performed

Parameters:
milli - A positive number of milliseconds, which corresponds to MILLISECOND

isInitialized

public boolean isInitialized()
Indicates whether this time object is initialized with a time value or not

Returns:
True if this time object holds a time value (which is mostly the case) or false if no value is currently associated with this time object (after a call to reset() for example

getField

public int getField(int timeField)
Retrieves a particular time field. This methods wraps all the get() methods, where can be replaced by Year, Month, Day, Hour,Minute, Second or Millisecond

Parameters:
timeField - The field identifier to retrieve from, among:
  • Year: Calendar.YEAR
  • Month: Calendar.MONTH
  • Day: Calendar.DAY_OF_MONTH
  • Hour: Calendar.HOUR_OF_DAY
  • Minute: Calendar.MINUTE
  • Second: Calendar.SECOND
  • Millisecond: Calendar.MILLISECOND
Returns:
The corresponding field value. Current number of milliseconds is returned in case the given field value is unknown

getYear

public int getYear()

getMonth

public int getMonth()

getDay

public int getDay()

getHour

public int getHour()

getMinute

public int getMinute()

getSecond

public int getSecond()

getMillisecond

public int getMillisecond()

getTimeZone

public java.lang.String getTimeZone()
Returns the current time zone identifier

Returns:
This time zone ID, such as "GMT+01:00". Default time zone corresponds to GMT (GMT+0000)

getValue

public java.util.Calendar getValue()
Returns the date value enclosed within this time object

Returns:
The internal date of this time object. This date must not be null

reset

public void reset()

Disables time fields values so that isInitialized() returns false.

Note that this operation does not initialize the current time zone to its default value


setTimeFormat

public void setTimeFormat(ASN1TimeFormat tf)
Sets the format for printing or encoding among the proposed formats of this TIME object

Parameters:
tf - An encoding format provided by this TIME object. An out-of-range format is equivalent to set to default format (FORMAT_0)

getTimeFormat

public ASN1TimeFormat getTimeFormat()
Returns the printing (or encoding) format of this TIME object

Returns:
The current format, among the proposed formats for this TIME object. Default format is FORMAT_0

duplicate

public ASN1TimeValue duplicate()
Creates a copy of this time value

Returns:
Another time value such that all its internal attributes have been duplicated from this time value

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(ASN1TimeFormat format,
                                 boolean shortYear)