/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ExsltDatetime.java,v 1.2.4.1 2005/09/10 18:50:49 jeffsuttor Exp $
*/
/**
* This class contains EXSLT dates and times extension functions.
* It is accessed by specifying a namespace URI as follows:
* <pre>
* xmlns:datetime="http://exslt.org/dates-and-times"
* </pre>
*
* The documentation for each function has been copied from the relevant
* EXSLT Implementer page.
*
* @see <a href="http://www.exslt.org/">EXSLT</a>
* @xsl.usage general
*/
public class ExsltDatetime
{
// Datetime formats (era and zone handled separately).
static final String d = "yyyy-MM-dd";
static final String t = "HH:mm:ss";
/**
* lexical representation of xs:dateTime in
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">[3.2.7 dateTime]</a> of
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a> and
* <a href="http://www.iso.ch/markete/8601.pdf">[ISO 8601]</a> for details.
* Universal Time or a + or - followed by the difference between the difference from UTC
* represented as hh:mm.
*/
{
// Format for date and time.
// Must also include offset from UTF.
// Get the offset (in milliseconds).
// If there is no offset, we have "Coordinated
// Universal Time."
if (offset == 0)
else
{
// Convert milliseconds to hours and minutes
// In a few cases, the time zone may be +/-hh:30.
}
}
/**
* Represent the hours and minutes with two-digit strings.
* @param q hrs or minutes.
* @return two-digit String representation of hrs or minutes.
*/
{
}
/**
* returned by date:date-time is used as a default argument.
* lexical representation of xs:dateTime in
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">[3.2.7 dateTime]</a> of
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* If the argument is not in either of these formats, date:date returns an empty string ('').
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a> and
* <a href="http://www.iso.ch/markete/8601.pdf">[ISO 8601]</a> 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.
* 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
{
return EMPTY_STR;
dateFormat.setLenient(false);
return EMPTY_STR;
else
}
/**
* See above.
*/
{
}
/**
* returned by date:date-time is used as a default argument.
* lexical representation of xs:dateTime in
* <a href="http://www.w3.org/TR/xmlschema-2/#dateTime">[3.2.7 dateTime]</a> of
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* If the argument string is not in this format, date:time returns an empty string ('').
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a> and
* <a href="http://www.iso.ch/markete/8601.pdf">[ISO 8601]</a> for details.
* The date is returned as a string with a lexical representation as defined for xs:time in
* <a href="http://www.w3.org/TR/xmlschema-2/#time">[3.2.8 time]</a> 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.
* 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
{
return EMPTY_STR;
}
/**
* See above.
*/
{
// The datetime() function returns the zone on the datetime string. If we
// append it, we get the zone substring duplicated.
// Fix for JIRA 2013
// String zone = datetime.substring(getZoneStart(datetime));
// return (time + zone);
return (time);
}
/**
* The date:year function returns the year of a date as a number. If no
* date:date-time is used as a default argument.
* string in the format defined as the lexical representation of xs:dateTime in one
* of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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)
*/
throws ParseException
{
return yr;
else
return -yr;
}
/**
* See above.
*/
public static double year()
{
}
/**
* The date:month-in-year function returns the month of a date as a number. If no argument
* as a default argument.
* string in the format defined as the lexical representation of xs:dateTime in one of
* the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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--)
* xs:gMonthDay (--MM-DD)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double monthInYear()
{
}
/**
* The date:week-in-year function returns the week of the year as a number. If no argument
* 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.
* defined as the lexical representation of xs:dateTime in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>. The
* permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double weekInYear()
{
}
/**
* 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
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double dayInYear()
{
}
/**
* The date:day-in-month function returns the day of a date as a number.
* by date:date-time is used the default argument.
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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)
*/
throws ParseException
{
return day;
}
/**
* See above.
*/
public static double dayInMonth()
{
}
/**
* 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).
* by date:date-time is used the default argument.
* in the format defined as the lexical representation of xs:dateTime in one
* of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double dayOfWeekInMonth()
{
}
/**
* The date:day-in-week function returns the day of the week given in a
* as returned by date:date-time is used the default argument.
* in the format defined as the lexical representation of xs:dateTime in one
* of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
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
{
}
/**
* See above.
*/
public static double dayInWeek()
{
}
/**
* The date:hour-in-day function returns the hour of the day as a number.
* by date:date-time is used the default argument.
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:time (hh:mm:ss)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double hourInDay()
{
}
/**
* The date:minute-in-hour function returns the minute of the hour
* as a number. If no argument is given, then the current local
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:time (hh:mm:ss)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double minuteInHour()
{
}
/**
* The date:second-in-minute function returns the second of the minute
* as a number. If no argument is given, then the current local
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:time (hh:mm:ss)
*/
throws ParseException
{
}
/**
* See above.
*/
public static double secondInMinute()
{
}
/**
* 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
* right-truncated string in the format defined as the lexical representation
* of xs:dateTime in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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)
*/
throws ParseException
{
}
/**
* See above.
*/
public static boolean leapYear()
{
}
/**
* The date:month-name function returns the full name of the month of a date.
* date:date-time is used the default argument.
* string in the format defined as the lexical representation of xs:dateTime in
* one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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--)
* 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
{
return EMPTY_STR;
}
/**
* See above.
*/
{
return getNameOrAbbrev(format);
}
/**
* The date:month-abbreviation function returns the abbreviation of the month of
* by date:date-time is used the default argument.
* string in the format defined as the lexical representation of xs:dateTime in
* one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* 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--)
* 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
{
return EMPTY_STR;
}
/**
* See above.
*/
{
return getNameOrAbbrev(format);
}
/**
* The date:day-name function returns the full name of the day of the week
* as returned by date:date-time is used the default argument.
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
* 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
{
return EMPTY_STR;
}
/**
* See above.
*/
{
return getNameOrAbbrev(format);
}
/**
* 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
* string in the format defined as the lexical representation of xs:dateTime
* in one of the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* xs:dateTime (CCYY-MM-DDThh:mm:ss)
* xs:date (CCYY-MM-DD)
* ('') 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
{
return EMPTY_STR;
}
/**
* See above.
*/
{
return getNameOrAbbrev(format);
}
/**
* 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.
*/
{
{
}
int z = getZoneStart(datetime);
if (z > 0)
{
}
else if (z == -2)
//System.out.println("'" + leader + "' " + datetime + " " + zone);
}
/**
* 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.
*/
{
{
try
{
dateFormat.setLenient(false);
}
catch (ParseException pe)
{
return -2; // Invalid.
}
}
return -1; // No zone information.
}
/**
* Attempt to parse an input string with the allowed formats, returning
* null if none of the formats work.
*/
throws ParseException
{
{
try
{
dateFormat.setLenient(false);
}
catch (ParseException pe)
{
}
}
return null;
}
/**
* Parse the input string and return the corresponding calendar field
* number.
*/
throws ParseException
{
cal.setLenient(false);
// Try the allowed formats, from longest to shortest.
}
/**
* Get the full name or abbreviation of the month or day.
*/
throws ParseException
{
{
try
{
dateFormat.setLenient(false);
}
catch (ParseException pe)
{
}
}
return "";
}
/**
* Get the full name or abbreviation for the current month or day
* (no input string).
*/
{
}
/**
* <p>
* the formats defined in
* <a href="http://www.w3.org/TR/xmlschema-2/">[XML Schema Part 2: Datatypes]</a>.
* The permitted formats are as follows:
* <ul>
* <li>xs:dateTime (CCYY-MM-DDThh:mm:ss)
* <li>xs:date (CCYY-MM-DD)
* <li>xs:time (hh:mm:ss)
* <li>xs:gYearMonth (CCYY-MM)
* <li>xs:gYear (CCYY)
* <li>xs:gMonthDay (--MM-DD)
* <li>xs:gMonth (--MM--)
* <li>xs:gDay (---DD)
* </ul>
* The second argument is a string that gives the format pattern used to
* format the date. The format pattern must be in the syntax specified by
* the JDK 1.1 SimpleDateFormat class. The format pattern string is
* interpreted as described for the JDK 1.1 SimpleDateFormat class.
* <p>
* xs:time, or xs:dateTime) then any missing components are assumed to be as
* follows: if no month is specified, it is given a month of 01; if no day
* is specified, it is given a day of 01; if no time is specified, it is
* given a time of 00:00:00.
* <p>
* xs:gMonth or xs:gDay) and the format pattern has a token that uses a
* is replaced with an empty string ('') within the result.
*
* The author is Helg Bredow (helg.bredow@kalido.com)
*/
{
// Get the timezone information if it was supplied and modify the
// dateTime so that SimpleDateFormat will understand it.
{
zone = "z";
}
{
{
}
else
{
}
zone = "z";
// Need to adjust it since SimpleDateFormat requires GMT+hh:mm but
// we have +hh:mm.
}
else
{
// Assume local time.
zone = "";
// Leave off the timezone since SimpleDateFormat will assume local
// time if time zone is not included.
}
// Try the time format first. We need to do this to prevent
// SimpleDateFormat from interpreting a time as a year. i.e we just need
// to check if it's a time before we check it's a year.
try
{
inFormat.setLenient(false);
}
catch (ParseException pe)
{
}
// Try the right truncated formats.
{
try
{
inFormat.setLenient(false);
}
catch (ParseException pe)
{
}
}
// Now try the left truncated ones. The Java format() function doesn't
// return the correct strings in this case. We strip any pattern
// symbols that shouldn't be output so that they are not defaulted to
// inappropriate values in the output.
try
{
inFormat.setLenient(false);
}
catch (ParseException pe)
{
}
try
{
inFormat.setLenient(false);
}
catch (ParseException pe)
{
}
try
{
inFormat.setLenient(false);
}
catch (ParseException pe)
{
}
return EMPTY_STR;
}
/**
* Strips occurrences of the given character from a date format pattern.
* @param symbols list of symbols to strip.
* @param pattern
* @return
*/
{
int quoteSemaphore = 0;
int i = 0;
{
if (ch == '\'')
{
// Assume it's an openening quote so simply copy the quoted
// text to the result. There is nothing to strip here.
if (endQuote == -1)
{
}
i = endQuote++;
}
{
// The char needs to be stripped.
i++;
}
else
{
i++;
}
}
}
}