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 <DOT>, <COMMA>, and <PLUS> 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 <g-time-zone> is used;
otherwise, the value represents a local time in the time zone
indicated by <g-differential>. In the latter case, coordinated
universal time can be calculated by subtracting the differential from
the local time. The "Z" form of <g-time-zone> SHOULD be used in
preference to <g-differential>.
If <minute> is omitted, then <fraction> represents a fraction of an
hour; otherwise, if <second> and <leap-second> are omitted, then
<fraction> represents a fraction of a minute; otherwise, <fraction>
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.
| Modifier and Type | Class and Description |
|---|---|
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.
|
| Modifier and Type | Field and Description |
|---|---|
private Calendar |
calendar
The calendar
|
private static Date |
INFINITE
A Date far in the future, when Micro$oft would have vanished for a long time...
|
private GeneralizedTime.Format |
upFormat
The user provided format
|
private GeneralizedTime.FractionDelimiter |
upFractionDelimiter
The user provided fraction delimiter
|
private int |
upFractionLength
the user provided fraction length
|
private String |
upGeneralizedTime
The user provided value
|
private GeneralizedTime.TimeZoneFormat |
upTimeZoneFormat
The user provided time zone format
|
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(GeneralizedTime other)
Compares this GeneralizedTime object with the specified GeneralizedTime object.
|
boolean |
equals(Object obj) |
private String |
getAllDigits(int startIndex) |
Calendar |
getCalendar()
Gets the calendar.
|
Date |
getDate() |
static Date |
getDate(String zuluTime)
Get a Date instance from a given String
|
int |
getDay() |
private GeneralizedTime.Format |
getFormatWithoutFraction(GeneralizedTime.Format f)
Gets the corresponding format with fraction.
|
int |
getFraction() |
private String |
getFraction(int startIndex) |
int |
getHour() |
int |
getMinutes() |
int |
getMonth() |
int |
getSeconds() |
long |
getTime() |
int |
getYear() |
int |
hashCode() |
private void |
parseDay() |
private void |
parseFractionDelmiter(int fractionDelimiterPos) |
private void |
parseFractionOfHour() |
private void |
parseFractionOfMinute() |
private void |
parseFractionOfSecond() |
private void |
parseHour() |
private void |
parseMinute() |
private void |
parseMonth() |
private void |
parseSecond() |
private void |
parseTimezone(int pos) |
private void |
parseYear() |
private void |
setUp(Calendar newCalendar) |
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 |
toGeneralizedTimeWithoutFraction()
Returns the string representation of this generalized time.
|
String |
toString() |
private static final Date INFINITE
private String upGeneralizedTime
private GeneralizedTime.Format upFormat
private GeneralizedTime.TimeZoneFormat upTimeZoneFormat
private GeneralizedTime.FractionDelimiter upFractionDelimiter
private int upFractionLength
private Calendar calendar
public GeneralizedTime(Date date)
date - the dateGeneralizedTime(Calendar)public GeneralizedTime(Calendar calendar)
Format.YEAR_MONTH_DAY_HOUR_MIN_SECas default format and
TimeZoneFormat.Zas default time zone format.
calendar - the calendar containing the date, time and timezone informationpublic GeneralizedTime(String generalizedTime) throws ParseException
generalizedTime - the generalized timeParseException - if the given generalized time can't be parsed.private void setUp(Calendar newCalendar)
private void parseTimezone(int pos)
throws ParseException
ParseExceptionprivate void parseFractionOfSecond()
throws ParseException
ParseExceptionprivate void parseFractionOfMinute()
throws ParseException
ParseExceptionprivate void parseFractionOfHour()
throws ParseException
ParseExceptionprivate void parseFractionDelmiter(int fractionDelimiterPos)
private String getFraction(int startIndex) throws ParseException
ParseExceptionprivate String getAllDigits(int startIndex)
private void parseSecond()
throws ParseException
ParseExceptionprivate void parseMinute()
throws ParseException
ParseExceptionprivate void parseHour()
throws ParseException
ParseExceptionprivate void parseDay()
throws ParseException
ParseExceptionprivate void parseMonth()
throws ParseException
ParseExceptionprivate void parseYear()
throws ParseException
ParseExceptionpublic String toGeneralizedTime()
public String toGeneralizedTimeWithoutFraction()
private GeneralizedTime.Format getFormatWithoutFraction(GeneralizedTime.Format f)
f - the formatpublic String toGeneralizedTime(GeneralizedTime.Format format, GeneralizedTime.FractionDelimiter fractionDelimiter, int fractionLength, GeneralizedTime.TimeZoneFormat timeZoneFormat)
format - the target formatfractionDelimiter - the target fraction delimiter, may be nullfractionLength - the fraction lengthtimeZoneFormat - the target time zone formatpublic Calendar getCalendar()
GeneralizedTime settings.public int compareTo(GeneralizedTime other)
compareTo in interface Comparable<GeneralizedTime>other - the other GeneralizedTime objectComparable.compareTo(java.lang.Object)public long getTime()
public Date getDate()
public int getYear()
public int getMonth()
public int getDay()
public int getHour()
public int getMinutes()
public int getSeconds()
public int getFraction()
public static Date getDate(String zuluTime) throws ParseException
zuluTime - The time as a StringParseException - If the String is not a valid dateCopyright © 2003–2017 The Apache Software Foundation. All rights reserved.