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| Name | Type | Description |
$date |
xs:anyAtomicType? |
the date or year |
| return value |
xs:boolean |
XQuery Function Declaration| See XSLT definition. | | XQuery Syntax for January 2007 (1.0): |
|---|
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
} ; | | XQuery Syntax for July 2004 - November 2005 (CR): |
|---|
declare namespace functx = "http://www.functx.com";
declare function functx:is-leap-year
( $date as xdt: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
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function is-leap-year
( $date as xdt:anyAtomicType? ) as xs:boolean {
for $year in xs:integer(fn:substring(fn:string($date),1,4))
return ($year mod 4 = 0 and
$year mod 100 != 0) or
$year mod 400 = 0
} |
Examples| XQuery Example | Results |
|---|
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 AlsoHistory |
|