org.apache.directory.api.util
Class GeneralizedTime

java.lang.Object
  extended by org.apache.directory.api.util.GeneralizedTime
All Implemented Interfaces:
Comparable<GeneralizedTime>

public class GeneralizedTime
extends Object
implements Comparable<GeneralizedTime>

This class represents the generalized time syntax as defined in RFC 4517 section 3.3.13.

The date, time and time zone information is internally backed by an Calendar object

Leap seconds are not supported, as Calendar does not support leap seconds.

 3.3.13.  Generalized Time

  A value of the Generalized Time syntax is a character string
  representing a date and time.  The LDAP-specific encoding of a value
  of this syntax is a restriction of the format defined in [ISO8601],
  and is described by the following ABNF:

     GeneralizedTime = century year month day hour
                          [ minute [ second / leap-second ] ]
                          [ fraction ]
                          g-time-zone

     century = 2(%x30-39) ; "00" to "99"
     year    = 2(%x30-39) ; "00" to "99"
     month   =   ( %x30 %x31-39 ) ; "01" (January) to "09"
               / ( %x31 %x30-32 ) ; "10" to "12"
     day     =   ( %x30 %x31-39 )    ; "01" to "09"
               / ( %x31-32 %x30-39 ) ; "10" to "29"
               / ( %x33 %x30-31 )    ; "30" to "31"
     hour    = ( %x30-31 %x30-39 ) / ( %x32 %x30-33 ) ; "00" to "23"
     minute  = %x30-35 %x30-39                        ; "00" to "59"

     second      = ( %x30-35 %x30-39 ) ; "00" to "59"
     leap-second = ( %x36 %x30 )       ; "60"

     fraction        = ( DOT / COMMA ) 1*(%x30-39)
     g-time-zone     = %x5A  ; "Z"
                       / g-differential
     g-differential  = ( MINUS / PLUS ) hour [ minute ]
     MINUS           = %x2D  ; minus sign ("-")

  The , , and  rules are defined in [RFC4512].

  The above ABNF allows character strings that do not represent valid
  dates (in the Gregorian calendar) and/or valid times (e.g., February
  31, 1994).  Such character strings SHOULD be considered invalid for
  this syntax.

  The time value represents coordinated universal time (equivalent to
  Greenwich Mean Time) if the "Z" form of  is used;
  otherwise, the value represents a local time in the time zone
  indicated by .  In the latter case, coordinated
  universal time can be calculated by subtracting the differential from
  the local time.  The "Z" form of  SHOULD be used in
  preference to .

  If  is omitted, then  represents a fraction of an
  hour; otherwise, if  and  are omitted, then
   represents a fraction of a minute; otherwise, 
  represents a fraction of a second.

     Examples:
        199412161032Z
        199412160532-0500

  Both example values represent the same coordinated universal time:
  10:32 AM, December 16, 1994.

  The LDAP definition for the Generalized Time syntax is:

     ( 1.3.6.1.4.1.1466.115.121.1.24 DESC 'Generalized Time' )

  This syntax corresponds to the GeneralizedTime ASN.1 type from
  [ASN.1], with the constraint that local time without a differential
  SHALL NOT be used.

 


Nested Class Summary
static class GeneralizedTime.Format
          The format of the generalized time.
static class GeneralizedTime.FractionDelimiter
          The fraction delimiter of the generalized time.
static class GeneralizedTime.TimeZoneFormat
          The time zone format of the generalized time.
 
Constructor Summary
GeneralizedTime(Calendar calendar)
          Creates a new instance of GeneralizedTime, based on the given Calendar object.
GeneralizedTime(Date date)
          Creates a new instance of GeneralizedTime by setting the date to an instance of Calendar.
GeneralizedTime(String generalizedTime)
          Creates a new instance of GeneralizedTime, based on the given generalized time string.
 
Method Summary
 int compareTo(GeneralizedTime other)
          Compares this GeneralizedTime object with the specified GeneralizedTime object.
 boolean equals(Object obj)
           
 Calendar getCalendar()
          Gets the calendar.
 Date getDate()
           
static Date getDate(String zuluTime)
           
 int getDay()
           
 int getHour()
           
 int getMinutes()
           
 int getMonth()
           
 int getSeconds()
           
 long getTime()
           
 int getYear()
           
 int hashCode()
           
 String toGeneralizedTime()
          Returns the string representation of this generalized time.
 String toGeneralizedTime(GeneralizedTime.Format format, GeneralizedTime.FractionDelimiter fractionDelimiter, int fractionLength, GeneralizedTime.TimeZoneFormat timeZoneFormat)
          Returns the string representation of this generalized time.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneralizedTime

public GeneralizedTime(Date date)
Creates a new instance of GeneralizedTime by setting the date to an instance of Calendar.

Parameters:
date - the date
See Also:
GeneralizedTime(Calendar)

GeneralizedTime

public GeneralizedTime(Calendar calendar)
Creates a new instance of GeneralizedTime, based on the given Calendar object. Uses
Format.YEAR_MONTH_DAY_HOUR_MIN_SEC
as default format and
TimeZoneFormat.Z
as default time zone format.

Parameters:
calendar - the calendar containing the date, time and timezone information

GeneralizedTime

public GeneralizedTime(String generalizedTime)
                throws ParseException
Creates a new instance of GeneralizedTime, based on the given generalized time string.

Parameters:
generalizedTime - the generalized time
Throws:
ParseException - if the given generalized time can't be parsed.
Method Detail

toGeneralizedTime

public String toGeneralizedTime()
Returns the string representation of this generalized time. This method uses the same format as the user provided format.

Returns:
the string representation of this generalized time

toGeneralizedTime

public String toGeneralizedTime(GeneralizedTime.Format format,
                                GeneralizedTime.FractionDelimiter fractionDelimiter,
                                int fractionLength,
                                GeneralizedTime.TimeZoneFormat timeZoneFormat)
Returns the string representation of this generalized time.

Parameters:
format - the target format
fractionDelimiter - the target fraction delimiter, may be null
fractionLength - the fraction length
timeZoneFormat - the target time zone format
Returns:
the string

getCalendar

public Calendar getCalendar()
Gets the calendar. It could be used to manipulate this GeneralizedTime settings.

Returns:
the calendar

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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

compareTo

public int compareTo(GeneralizedTime other)
Compares this GeneralizedTime object with the specified GeneralizedTime object.

Specified by:
compareTo in interface Comparable<GeneralizedTime>
Parameters:
other - the other GeneralizedTime object
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
See Also:
Comparable.compareTo(java.lang.Object)

getTime

public long getTime()

getDate

public Date getDate()

getYear

public int getYear()

getMonth

public int getMonth()

getDay

public int getDay()

getHour

public int getHour()

getMinutes

public int getMinutes()

getSeconds

public int getSeconds()

getDate

public static Date getDate(String zuluTime)
                    throws ParseException
Parameters:
zuluTime -
Returns:
Throws:
ParseException


Copyright © 2003-2013 The Apache Software Foundation. All Rights Reserved.