org.apache.xalan.lib
Class ExsltDatetime

java.lang.Object
  extended byorg.apache.xalan.lib.ExsltDatetime

public class ExsltDatetime
extends Object

This class contains EXSLT dates and times extension functions. It is accessed by specifying a namespace URI as follows:

    xmlns:datetime="http://exslt.org/dates-and-times"
 
The documentation for each function has been copied from the relevant EXSLT Implementer page.

See Also:
EXSLT

Field Summary
(package private) static String d
           
(package private) static String dt
           
(package private) static String gd
           
(package private) static String gm
           
(package private) static String gmd
           
(package private) static String gy
           
(package private) static String gym
           
(package private) static String t
           
 
Constructor Summary
ExsltDatetime()
           
 
Method Summary
static XString date()
          See above.
static XString date(String datetimeIn)
          The date:date function returns the date specified in the date/time string given as the argument.
static XString dateTime()
          The date:date-time function returns the current date and time as a date/time string.
static XString dayAbbreviation()
          See above.
static XString dayAbbreviation(String datetimeIn)
          The date:day-abbreviation function returns the abbreviation of the day of the week of a date.
static XNumber dayInMonth()
          See above.
static XNumber dayInMonth(String datetimeIn)
          The date:day-in-month function returns the day of a date as a number.
static XNumber dayInWeek()
          See above.
static XNumber dayInWeek(String datetimeIn)
          The date:day-in-week function returns the day of the week given in a date as a number.
static XNumber dayInYear()
          See above.
static XNumber dayInYear(String datetimeIn)
          The date:day-in-year function returns the day of a date in a year as a number.
static XString dayName()
          See above.
static XString dayName(String datetimeIn)
          The date:day-name function returns the full name of the day of the week of a date.
static XNumber dayOfWeekInMonth()
          See above.
static XNumber dayOfWeekInMonth(String datetimeIn)
          The date:day-of-week-in-month function returns the day-of-the-week in a month of a date as a number (e.g. 3 for the 3rd Tuesday in May).
private static String formatDigits(int q)
          Represent the hours and minutes with two-digit strings.
private static String[] getEraDatetimeZone(String in)
          Returns an array with the 3 components that a datetime input string may contain: - (for BC era), datetime, and zone.
private static String getNameOrAbbrev(String format)
          Get the full name or abbreviation for the current month or day (no input string).
private static String getNameOrAbbrev(String in, String[] formatsIn, String formatOut)
          Get the full name or abbreviation of the month or day.
private static double getNumber(String in, String[] formats, int calField)
          Parse the input string and return the corresponding calendar field number.
private static int getZoneStart(String datetime)
          Get the start of zone information if the input ends with 'Z' or +/-hh:mm.
static XNumber hourInDay()
          See above.
static XNumber hourInDay(String datetimeIn)
          The date:hour-in-day function returns the hour of the day as a number.
static XBoolean leapYear()
          See above.
static XObject leapYear(String datetimeIn)
          The date:leap-year function returns true if the year given in a date is a leap year.
static XNumber minuteInHour()
          See above.
static XNumber minuteInHour(String datetimeIn)
          The date:minute-in-hour function returns the minute of the hour as a number.
static XString monthAbbreviation()
          See above.
static XString monthAbbreviation(String datetimeIn)
          The date:month-abbreviation function returns the abbreviation of the month of a date.
static XNumber monthInYear()
          See above.
static XNumber monthInYear(String datetimeIn)
          The date:year function returns the month of a date as a number.
static XString monthName()
          See above.
static XString monthName(String datetimeIn)
          The date:month-name function returns the full name of the month of a date.
static XNumber secondInMinute()
          See above.
static XNumber secondInMinute(String datetimeIn)
          The date:second-in-minute function returns the second of the minute as a number.
private static Date testFormats(String in, String[] formats)
          Attempt to parse an input string with the allowed formats, returning null if none of the formats work.
static XString time()
          See above.
static XString time(String timeIn)
          The date:time function returns the time specified in the date/time string given as the argument.
static XNumber weekInYear()
          See above.
static XNumber weekInYear(String datetimeIn)
          The date:week-in-year function returns the week of the year as a number.
static XNumber year()
          See above.
static XNumber year(String datetimeIn)
          The date:year function returns the year of a date as a number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dt

static final String dt
See Also:
Constant Field Values

d

static final String d
See Also:
Constant Field Values

gym

static final String gym
See Also:
Constant Field Values

gy

static final String gy
See Also:
Constant Field Values

gmd

static final String gmd
See Also:
Constant Field Values

gm

static final String gm
See Also:
Constant Field Values

gd

static final String gd
See Also:
Constant Field Values

t

static final String t
See Also:
Constant Field Values
Constructor Detail

ExsltDatetime

public ExsltDatetime()
Method Detail

dateTime

public static XString dateTime()
The date:date-time function returns the current date and time as a date/time string. The date/time string that's returned must be a string in the format defined as the lexical representation of xs:dateTime in [3.2.7 dateTime] of [XML Schema Part 2: Datatypes]. The date/time format is basically CCYY-MM-DDThh:mm:ss, although implementers should consult [XML Schema Part 2: Datatypes] and [ISO 8601] for details. The date/time string format must include a time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the difference from UTC represented as hh:mm.


formatDigits

private static String formatDigits(int q)
Represent the hours and minutes with two-digit strings.

Parameters:
q - hrs or minutes.
Returns:
two-digit String representation of hrs or minutes.

date

public static XString date(String datetimeIn)
                    throws ParseException
The date:date function returns the date specified in the date/time string given as the argument. If no argument is given, then the current local date/time, as returned by date:date-time is used as a default argument. The date/time string that's returned must be a string in the format defined as the lexical representation of xs:dateTime in [3.2.7 dateTime] of [XML Schema Part 2: Datatypes]. If the argument is not in either of these formats, date:date returns an empty string (''). The date/time format is basically CCYY-MM-DDThh:mm:ss, although implementers should consult [XML Schema Part 2: Datatypes] and [ISO 8601] for details. The date is returned as a string with a lexical representation as defined for xs:date in [3.2.9 date] of [XML Schema Part 2: Datatypes]. The date format is basically CCYY-MM-DD, although implementers should consult [XML Schema Part 2: Datatypes] and [ISO 8601] for details. If no argument is given or the argument date/time specifies a time zone, then the date string format must include a time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the difference from UTC represented as hh:mm. If an argument is specified and it does not specify a time zone, then the date string format must not include a time zone.

Throws:
ParseException

date

public static XString date()
See above.


time

public static XString time(String timeIn)
                    throws ParseException
The date:time function returns the time specified in the date/time string given as the argument. If no argument is given, then the current local date/time, as returned by date:date-time is used as a default argument. The date/time string that's returned must be a string in the format defined as the lexical representation of xs:dateTime in [3.2.7 dateTime] of [XML Schema Part 2: Datatypes]. If the argument string is not in this format, date:time returns an empty string (''). The date/time format is basically CCYY-MM-DDThh:mm:ss, although implementers should consult [XML Schema Part 2: Datatypes] and [ISO 8601] for details. The date is returned as a string with a lexical representation as defined for xs:time in [3.2.8 time] of [XML Schema Part 2: Datatypes]. The time format is basically hh:mm:ss, although implementers should consult [XML Schema Part 2: Datatypes] and [ISO 8601] for details. If no argument is given or the argument date/time specifies a time zone, then the time string format must include a time zone, either a Z to indicate Coordinated Universal Time or a + or - followed by the difference between the difference from UTC represented as hh:mm. If an argument is specified and it does not specify a time zone, then the time string format must not include a time zone.

Throws:
ParseException

time

public static XString time()
See above.


year

public static XNumber year(String datetimeIn)
                    throws ParseException
The date:year function returns the year of a date as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used as a default argument. The date/time string specified as the first argument must be a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gYearMonth (CCYY-MM) xs:gYear (CCYY) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

year

public static XNumber year()
See above.


monthInYear

public static XNumber monthInYear(String datetimeIn)
                           throws ParseException
The date:year function returns the month of a date as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used as a default argument. The date/time string specified as the first argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gYearMonth (CCYY-MM) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

monthInYear

public static XNumber monthInYear()
See above.


weekInYear

public static XNumber weekInYear(String datetimeIn)
                          throws ParseException
The date:week-in-year function returns the week of the year as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used as the default argument. For the purposes of numbering, counting follows ISO 8601: week 1 in a year is the week containing the first Thursday of the year, with new weeks beginning on a Monday. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

weekInYear

public static XNumber weekInYear()
See above.


dayInYear

public static XNumber dayInYear(String datetimeIn)
                         throws ParseException
The date:day-in-year function returns the day of a date in a year as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

dayInYear

public static XNumber dayInYear()
See above.


dayInMonth

public static XNumber dayInMonth(String datetimeIn)
                          throws ParseException
The date:day-in-month function returns the day of a date as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gMonthDay (--MM-DD) xs:gDay (---DD) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

dayInMonth

public static XNumber dayInMonth()
See above.


dayOfWeekInMonth

public static XNumber dayOfWeekInMonth(String datetimeIn)
                                throws ParseException
The date:day-of-week-in-month function returns the day-of-the-week in a month of a date as a number (e.g. 3 for the 3rd Tuesday in May). If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

dayOfWeekInMonth

public static XNumber dayOfWeekInMonth()
See above.


dayInWeek

public static XNumber dayInWeek(String datetimeIn)
                         throws ParseException
The date:day-in-week function returns the day of the week given in a date as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then NaN is returned. The numbering of days of the week starts at 1 for Sunday, 2 for Monday and so on up to 7 for Saturday.

Throws:
ParseException

dayInWeek

public static XNumber dayInWeek()
See above.


hourInDay

public static XNumber hourInDay(String datetimeIn)
                         throws ParseException
The date:hour-in-day function returns the hour of the day as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:time (hh:mm:ss) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

hourInDay

public static XNumber hourInDay()
See above.


minuteInHour

public static XNumber minuteInHour(String datetimeIn)
                            throws ParseException
The date:minute-in-hour function returns the minute of the hour as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:time (hh:mm:ss) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

minuteInHour

public static XNumber minuteInHour()
See above.


secondInMinute

public static XNumber secondInMinute(String datetimeIn)
                              throws ParseException
The date:second-in-minute function returns the second of the minute as a number. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:time (hh:mm:ss) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

secondInMinute

public static XNumber secondInMinute()
See above.


leapYear

public static XObject leapYear(String datetimeIn)
                        throws ParseException
The date:leap-year function returns true if the year given in a date is a leap year. If no argument is given, then the current local date/time, as returned by date:date-time is used as a default argument. The date/time string specified as the first argument must be a right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gYearMonth (CCYY-MM) xs:gYear (CCYY) If the date/time string is not in one of these formats, then NaN is returned.

Throws:
ParseException

leapYear

public static XBoolean leapYear()
See above.


monthName

public static XString monthName(String datetimeIn)
                         throws ParseException
The date:month-name function returns the full name of the month of a date. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gYearMonth (CCYY-MM) xs:gMonth (--MM--) If the date/time string is not in one of these formats, then an empty string ('') is returned. The result is an English month name: one of 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November' or 'December'.

Throws:
ParseException

monthName

public static XString monthName()
See above.


monthAbbreviation

public static XString monthAbbreviation(String datetimeIn)
                                 throws ParseException
The date:month-abbreviation function returns the abbreviation of the month of a date. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) xs:gYearMonth (CCYY-MM) xs:gMonth (--MM--) If the date/time string is not in one of these formats, then an empty string ('') is returned. The result is a three-letter English month abbreviation: one of 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov' or 'Dec'. An implementation of this extension function in the EXSLT date namespace must conform to the behaviour described in this document.

Throws:
ParseException

monthAbbreviation

public static XString monthAbbreviation()
See above.


dayName

public static XString dayName(String datetimeIn)
                       throws ParseException
The date:day-name function returns the full name of the day of the week of a date. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then the empty string ('') is returned. The result is an English day name: one of 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday' or 'Friday'. An implementation of this extension function in the EXSLT date namespace must conform to the behaviour described in this document.

Throws:
ParseException

dayName

public static XString dayName()
See above.


dayAbbreviation

public static XString dayAbbreviation(String datetimeIn)
                               throws ParseException
The date:day-abbreviation function returns the abbreviation of the day of the week of a date. If no argument is given, then the current local date/time, as returned by date:date-time is used the default argument. The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of xs:dateTime in one of the formats defined in [XML Schema Part 2: Datatypes]. The permitted formats are as follows: xs:dateTime (CCYY-MM-DDThh:mm:ss) xs:date (CCYY-MM-DD) If the date/time string is not in one of these formats, then the empty string ('') is returned. The result is a three-letter English day abbreviation: one of 'Sun', 'Mon', 'Tue', 'Wed', 'Thu' or 'Fri'. An implementation of this extension function in the EXSLT date namespace must conform to the behaviour described in this document.

Throws:
ParseException

dayAbbreviation

public static XString dayAbbreviation()
See above.


getEraDatetimeZone

private static String[] getEraDatetimeZone(String in)
Returns an array with the 3 components that a datetime input string may contain: - (for BC era), datetime, and zone. If the zone is not valid, return null for that component.


getZoneStart

private static int getZoneStart(String datetime)
Get the start of zone information if the input ends with 'Z' or +/-hh:mm. If a zone string is not found, return -1; if the zone string is invalid, return -2.


testFormats

private static Date testFormats(String in,
                                String[] formats)
                         throws ParseException
Attempt to parse an input string with the allowed formats, returning null if none of the formats work. Input formats are passed in longest to shortest, so if any parse operation fails with a parse error in the string, can immediately return null.

Throws:
ParseException

getNumber

private static double getNumber(String in,
                                String[] formats,
                                int calField)
                         throws ParseException
Parse the input string and return the corresponding calendar field number.

Throws:
ParseException

getNameOrAbbrev

private static String getNameOrAbbrev(String in,
                                      String[] formatsIn,
                                      String formatOut)
                               throws ParseException
Get the full name or abbreviation of the month or day.

Throws:
ParseException

getNameOrAbbrev

private static String getNameOrAbbrev(String format)
Get the full name or abbreviation for the current month or day (no input string).