home contribute faq download

FunctX XQuery Functions

functx:is-leap-year

Whether a date falls in a leap year

Google
Webxqueryfunctions.com

Description

The functx:is-leap-year function returns true if $date falls in a leap year.

The first four characters of the string value of $date must be the year. For example, the argument can be a value of type xs:date, xs:dateTime, or an xs:integer with four significant digits, or an xs:string or untyped value of the form YYYY or YYYY-MM-DD.

Arguments and Return Type

NameTypeDescription
$date xs:anyAtomicType? the date or year
return value xs:boolean

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:is-leap-year
  ( $date as xs:anyAtomicType? )  as xs:boolean {

    for $year in xs:integer(substring(string($date),1,4))
    return ($year mod 4 = 0 and
            $year mod 100 != 0) or
            $year mod 400 = 0
 } ;

Examples

XQuery ExampleResults
functx:is-leap-year(xs:date('2004-01-23'))
true
functx:is-leap-year(2004)
true
functx:is-leap-year('2005-02-15')
false

See Also

functx:last-day-of-monthThe last day of the month of a date

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery