-
-
Save mcfearsome/3422 to your computer and use it in GitHub Desktop.
.DS_Store |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
/* box model */ | |
BODY { | |
margin: 1em; | |
} | |
H1 { | |
padding: 0.3em 0.5em 0.3em 0.5em; | |
margin: 0em; | |
} | |
H2 { | |
padding: 0.2em 1em 0.2em 0.8em; | |
margin: 1em 0em 0em 0em; | |
} | |
H3 { | |
padding: 0.1em 1em 0.2em 0.8em; | |
margin: 0em; | |
} | |
H4 { | |
padding: 0em; | |
margin: 0.5em 1em; | |
} | |
H5 { | |
padding: 0em; | |
margin: 0em 1em; | |
} | |
P, TABLE { | |
margin: 0.5em 1em; | |
} | |
UL, OL { | |
margin: 0.5em 2em; | |
} | |
UL UL, UL OL, OL UL, OL OL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations UL { | |
margin: 0.5em 0em; | |
} | |
TD.implementations LI { | |
margin: 0em 2em; | |
} | |
LI { | |
margin: 0.5em 2em; | |
list-style-type: disc; | |
} | |
LI P { | |
margin: 0em; | |
} | |
DL { | |
margin: 0.5em 2em 1em 2em; | |
} | |
DT { | |
margin: 1em; | |
clear: both; | |
} | |
DD { | |
margin: -0.5em 0em -0.5em 2em; | |
} | |
DD UL, DD OL { | |
margin-left: 0em; | |
} | |
BLOCKQUOTE { | |
margin-left: 3em; | |
} | |
IMG { | |
position: relative; | |
} | |
TABLE { | |
width: 100%; | |
margin: 0em; | |
} | |
PRE { | |
padding: 0.5em 3em 0.5em 3em; | |
margin: 0em; | |
} | |
#content TD PRE { | |
padding: 0em; | |
} | |
PRE.copyright { | |
padding: 0em; | |
margin: 0em; | |
} | |
.issue { | |
padding: 0em 3em; | |
margin: 0em; | |
} | |
#menu { | |
width: 20%; | |
padding: 0em; | |
} | |
P.level1, P.level2, P.level3, P.level4 { | |
padding: 0em 1em; | |
margin: 0em; | |
} | |
P.level1 { | |
margin: 0em 0em 3px 0em; | |
} | |
P.level2 { | |
margin: 0em 0em 1px 0em; | |
} | |
P.level3 { | |
margin-left: 1em; | |
} | |
P.level4 { | |
margin-left: 2em; | |
} | |
#content TH, #content TD { | |
margin: 0em; | |
padding: 0em 0.5em; | |
} | |
#navigation, #content, #colophon P { | |
margin-top: 2px; | |
} | |
TD.implementations { | |
width: 25%; | |
} | |
/* fonts */ | |
BODY, TR { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1, H2, H3, H4, H5, H6 { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
} | |
H1 { | |
font-size: 173%; | |
font-weight: bold; | |
} | |
H2 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H3 { | |
font-size: 120%; | |
font-weight: bold; | |
} | |
H4 { | |
font-size: 100%; | |
font-weight: bold; | |
} | |
H5 { | |
font-size: 100% | |
font-weight: normal; | |
font-style: italic; | |
} | |
#navigation TD { | |
font-weight: bold; | |
} | |
DT { | |
font-weight: bold; | |
} | |
PRE, CODE { | |
font-size: 100%; | |
} | |
A:link, A:visited, A:active, A:hover { | |
font-weight: bold; | |
} | |
A.offsite:link, A.offsite:visited, A.offsite:active, A.offsite:hover { | |
font-weight: normal; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:hover { | |
font-weight: bold; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, P.level3 A:link, P.level3 A:visited { | |
font-weight: normal; | |
} | |
#menu P.level3, #menu P.level4 { | |
font-size: 83%; | |
} | |
#menu P.level4, P.level4 A:link, P.level4 A:visited { | |
font-weight: normal; | |
font-style: italic; | |
} | |
.note { | |
font-family: 'Trebuchet MS', Arial, sans-serif; | |
font-size: 100%; | |
font-style: italic; | |
} | |
#colophon { | |
font-size: 69%; | |
} | |
/* colours */ | |
BODY { | |
background: white; | |
color: black; | |
border: 0px none white; | |
} | |
/* this is to make Navigator fill the entire line */ | |
H1, #content { | |
border: 1px solid white; | |
width: 100%; | |
} | |
H1, H1 A:link, H1 A:visited, H1 A:active, H1 A:hover { | |
background: #401; | |
color: white; | |
} | |
H2 { | |
border-top: 5px solid white; | |
width: 100%; | |
} | |
H2, H2 A:link, H2 A:visited, H2 A:active, H2 A:hover { | |
background: #041; | |
color: white; | |
} | |
H3 { | |
border-top: 3px solid white; | |
width: 100%; | |
} | |
H3, H3 A:link, H3 A:visited, H3 A:active, H3 A:hover { | |
color: #041; | |
background: #EFE; | |
} | |
#content TABLE { | |
border-collapse: collapse; | |
} | |
#content TH { | |
background: #041; | |
color: white; | |
} | |
#content TD { | |
background: #EFE; | |
color: black; | |
border: 1px solid #041; | |
} | |
#content, #navigation { | |
background: #EFE; | |
color: black; | |
} | |
HR { | |
color: #041; | |
background: #041; | |
} | |
IMG, A:link IMG, A:visited IMG, A:hover IMG, A:active IMG { | |
border: 0px none white; | |
background: transparent; | |
} | |
A:link, A:visited, A:active, A:hover { | |
color: #052; | |
background: transparent; | |
border: 0px none white; | |
} | |
.note { | |
color: #333; | |
} | |
.note A:link, .note A:visited, .note A:hover { | |
background: transparent; | |
color: #041; | |
} | |
.error { | |
color: #C00; | |
} | |
#colophon { | |
color: #333; | |
background: #FEE; | |
} | |
#colophon A:link, #colophon A:visited, #colophon A:hover { | |
color: #401; | |
background: transparent; | |
} | |
TD.implementations { | |
border-left: 1px solid #041; | |
} | |
#menu { | |
background: #EEF; | |
color: #014; | |
} | |
#menu P.level1, P.level1 A:link, P.level1 A:visited, P.level1 A:active P.level1 A:hover { | |
background: #014; | |
color: white; | |
} | |
#menu P.level2, P.level2 A:link, P.level2 A:visited, P.level2 A:active P.level2 A:hover, | |
#menu P.level3, P.level3 A:link, P.level3 A:visited, P.level3 A:active P.level3 A:hover, | |
#menu P.level4, P.level4 A:link, P.level4 A:visited, P.level4 A:active P.level4 A:hover { | |
background: #EEF; | |
color: #014; | |
} | |
P.level2 A:hover, P.level3 A:hover, P.level4 A:hover { | |
text-decoration: underline; | |
} | |
/* text */ | |
OL OL LI { | |
list-style: lower-alpha; | |
} | |
TH { | |
text-align: left; | |
} | |
TD { | |
vertical-align: top; | |
} | |
#content TH, #content TD { | |
text-align: center; | |
} | |
#content TH.rowhead, #content TD.rowhead { | |
text-align: left; | |
} | |
H1 { | |
text-transform: uppercase; | |
} | |
H2 { | |
text-transform: uppercase; | |
} | |
H4 { | |
text-transform: lowercase; | |
} | |
#menu { | |
text-transform: lowercase; | |
} | |
#navigation TD { | |
text-transform: uppercase; | |
text-align: center; | |
} | |
A.offsite { | |
text-decoration: underline; | |
} | |
A, A.function, A.element { | |
text-decoration: none; | |
} |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<func:function name="date:add-duration"> | |
<xsl:param name="duration1" /> | |
<xsl:param name="duration2" /> | |
<xsl:variable name="du1-neg" select="starts-with($duration1, '-')" /> | |
<xsl:variable name="du1"> | |
<xsl:choose> | |
<xsl:when test="$du1-neg"><xsl:value-of select="substring($duration1, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2-neg" select="starts-with($duration2, '-')" /> | |
<xsl:variable name="du2"> | |
<xsl:choose> | |
<xsl:when test="$du2-neg"><xsl:value-of select="substring($duration2, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration2" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="duration"> | |
<xsl:if test="starts-with($du1, 'P') and | |
not(translate($du1, '0123456789PYMDTHS.', '')) and | |
starts-with($du2, 'P') and | |
not(translate($du2, '0123456789PYMDTHS.', ''))"> | |
<xsl:variable name="du1-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du1, 'T')"><xsl:value-of select="substring-before(substring($du1, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du1, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1-time"> | |
<xsl:if test="contains($du1, 'T')"><xsl:value-of select="substring-after($du1, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:variable name="du2-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du2, 'T')"><xsl:value-of select="substring-before(substring($du2, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du2, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2-time"> | |
<xsl:if test="contains($du2, 'T')"><xsl:value-of select="substring-after($du2, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:if test="(not($du1-date) or | |
(not(translate($du1-date, '0123456789YMD', '')) and | |
not(substring-after($du1-date, 'D')) and | |
(contains($du1-date, 'D') or | |
(not(substring-after($du1-date, 'M')) and | |
(contains($du1-date, 'M') or | |
not(substring-after($du1-date, 'Y'))))))) and | |
(not($du1-time) or | |
(not(translate($du1-time, '0123456789HMS.', '')) and | |
not(substring-after($du1-time, 'S')) and | |
(contains($du1-time, 'S') or | |
not(substring-after($du1-time, 'M')) and | |
(contains($du1-time, 'M') or | |
not(substring-after($du1-time, 'Y')))))) and | |
(not($du2-date) or | |
(not(translate($du2-date, '0123456789YMD', '')) and | |
not(substring-after($du2-date, 'D')) and | |
(contains($du2-date, 'D') or | |
(not(substring-after($du2-date, 'M')) and | |
(contains($du2-date, 'M') or | |
not(substring-after($du2-date, 'Y'))))))) and | |
(not($du2-time) or | |
(not(translate($du2-time, '0123456789HMS.', '')) and | |
not(substring-after($du2-time, 'S')) and | |
(contains($du2-time, 'S') or | |
not(substring-after($du2-time, 'M')) and | |
(contains($du2-time, 'M') or | |
not(substring-after($du2-time, 'Y'))))))"> | |
<xsl:variable name="du1y-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before($du1-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1m-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du1-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1d-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'M')"><xsl:value-of select="substring-before(substring-after($du1-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du1-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1h-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before($du1-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1min-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before(substring-after($du1-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1s-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'M')"><xsl:value-of select="substring-before(substring-after($du1-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before(substring-after($du1-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult1" select="($du1-neg * -2) + 1" /> | |
<xsl:variable name="du1y" select="$du1y-str * $mult1" /> | |
<xsl:variable name="du1m" select="$du1m-str * $mult1" /> | |
<xsl:variable name="du1d" select="$du1d-str * $mult1" /> | |
<xsl:variable name="du1h" select="$du1h-str * $mult1" /> | |
<xsl:variable name="du1min" select="$du1min-str * $mult1" /> | |
<xsl:variable name="du1s" select="$du1s-str * $mult1" /> | |
<xsl:variable name="du2y-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before($du2-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2m-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du2-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2d-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'M')"><xsl:value-of select="substring-before(substring-after($du2-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du2-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2h-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before($du2-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2min-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before(substring-after($du2-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2s-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'M')"><xsl:value-of select="substring-before(substring-after($du2-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before(substring-after($du2-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult2" select="($du2-neg * -2) + 1" /> | |
<xsl:variable name="du2y" select="$du2y-str * $mult2" /> | |
<xsl:variable name="du2m" select="$du2m-str * $mult2" /> | |
<xsl:variable name="du2d" select="$du2d-str * $mult2" /> | |
<xsl:variable name="du2h" select="$du2h-str * $mult2" /> | |
<xsl:variable name="du2min" select="$du2min-str * $mult2" /> | |
<xsl:variable name="du2s" select="$du2s-str * $mult2" /> | |
<xsl:variable name="min-s" select="60" /> | |
<xsl:variable name="hour-s" select="60 * 60" /> | |
<xsl:variable name="day-s" select="60 * 60 * 24" /> | |
<xsl:variable name="seconds" select="($du1s + $du2s) + | |
(($du1min + $du2min) * $min-s) + | |
(($du1h + $du2h) * $hour-s) + | |
(($du1d + $du2d) * $day-s)" /> | |
<xsl:variable name="months" select="($du1m + $du2m) + | |
(($du1y + $du2y) * 12)" /> | |
<xsl:choose> | |
<xsl:when test="($months * $seconds) < 0" /> | |
<xsl:when test="$months or $seconds"> | |
<xsl:if test="$months < 0 or $seconds < 0">-</xsl:if> | |
<xsl:text>P</xsl:text> | |
<xsl:variable name="m" select="$months * ((($months >= 0) * 2) - 1)" /> | |
<xsl:variable name="years" select="floor($m div 12)" /> | |
<xsl:variable name="mnths" select="$m - ($years * 12)" /> | |
<xsl:variable name="s" select="$seconds * ((($seconds >= 0) * 2) - 1)" /> | |
<xsl:variable name="days" select="floor($s div $day-s)" /> | |
<xsl:variable name="hours" select="floor(($s - ($days * $day-s)) div $hour-s)" /> | |
<xsl:variable name="mins" select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)" /> | |
<xsl:variable name="secs" select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)" /> | |
<xsl:if test="$years"> | |
<xsl:value-of select="$years" /> | |
<xsl:text>Y</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mnths"> | |
<xsl:value-of select="$mnths" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$days"> | |
<xsl:value-of select="$days" /> | |
<xsl:text>D</xsl:text> | |
</xsl:if> | |
<xsl:if test="$hours or $mins or $secs">T</xsl:if> | |
<xsl:if test="$hours"> | |
<xsl:value-of select="$hours" /> | |
<xsl:text>H</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mins"> | |
<xsl:value-of select="$mins" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$secs"> | |
<xsl:value-of select="$secs" /> | |
<xsl:text>S</xsl:text> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>P</xsl:otherwise> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<func:result select="string($duration)" /> | |
</func:function> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:add-duration - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/add-duration">add-duration</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>2<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.add-duration.xml">date.add-duration.xml</a><br/><b>Function Package: </b><a href="date.add-duration.zip">date.add-duration.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:add-duration</b>(<var>string</var>, <var>string</var>)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:add-duration</b>"> | |
<xsl:with-param name="duration1" select="<var>string</var>" /> | |
<xsl:with-param name="duration2" select="<var>string</var>" /> | |
</xsl:call-template></pre><div><p> | |
The <code>date:add-duration</code> function returns the duration resulting from adding two durations together. | |
</p><p> | |
Both arguments are strings in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If either argument is not in this format, the function returns an empty string (<code>''</code>). | |
</p><p> | |
The return value is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p> | |
The durations can usually be added by summing the numbers given for each of the components in the durations. However, if the durations are differently signed, then this sometimes results in durations that are impossible to express in this syntax (e.g. <code>'P1M'</code> + <code>'-P1D'</code>). In these cases, the function returns an empty string (<code>''</code>). | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:add-duration</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>2</td></tr></table><p> | |
The following implementations of <code>date:add-duration</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.add-duration.function.xsl.html">EXSLT Function</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-11</td><td><a href="date.add-duration.function.xsl">date.add-duration.function.xsl</a></td></tr><tr><td class="rowhead"><a href="date.add-duration.template.xsl.html">XSLT Template</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-11</td><td><a href="date.add-duration.template.xsl">date.add-duration.template.xsl</a></td></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Previous Version: </b><a href="date.add-duration.1.html">date.add-duration.1.html</a></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">2</td><td style="width: 5em;">2001-06-11</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Made it illegal to have an addition result in positive (years and) months and negative (days, hours, minutes and) seconds, or vice versa.</li><li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.1</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.2</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added libxslt implementation to the list.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/add-duration/date.add-duration.html">http://www.exslt.org/date/functions/add-duration/date.add-duration.html</a> last modified 2002-08-21</p></div></body></html> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<xsl:template name="date:add-duration"> | |
<xsl:param name="duration1" /> | |
<xsl:param name="duration2" /> | |
<xsl:variable name="du1-neg" select="starts-with($duration1, '-')" /> | |
<xsl:variable name="du1"> | |
<xsl:choose> | |
<xsl:when test="$du1-neg"><xsl:value-of select="substring($duration1, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2-neg" select="starts-with($duration2, '-')" /> | |
<xsl:variable name="du2"> | |
<xsl:choose> | |
<xsl:when test="$du2-neg"><xsl:value-of select="substring($duration2, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration2" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="duration"> | |
<xsl:if test="starts-with($du1, 'P') and | |
not(translate($du1, '0123456789PYMDTHS.', '')) and | |
starts-with($du2, 'P') and | |
not(translate($du2, '0123456789PYMDTHS.', ''))"> | |
<xsl:variable name="du1-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du1, 'T')"><xsl:value-of select="substring-before(substring($du1, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du1, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1-time"> | |
<xsl:if test="contains($du1, 'T')"><xsl:value-of select="substring-after($du1, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:variable name="du2-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du2, 'T')"><xsl:value-of select="substring-before(substring($du2, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du2, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2-time"> | |
<xsl:if test="contains($du2, 'T')"><xsl:value-of select="substring-after($du2, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:if test="(not($du1-date) or | |
(not(translate($du1-date, '0123456789YMD', '')) and | |
not(substring-after($du1-date, 'D')) and | |
(contains($du1-date, 'D') or | |
(not(substring-after($du1-date, 'M')) and | |
(contains($du1-date, 'M') or | |
not(substring-after($du1-date, 'Y'))))))) and | |
(not($du1-time) or | |
(not(translate($du1-time, '0123456789HMS.', '')) and | |
not(substring-after($du1-time, 'S')) and | |
(contains($du1-time, 'S') or | |
not(substring-after($du1-time, 'M')) and | |
(contains($du1-time, 'M') or | |
not(substring-after($du1-time, 'Y')))))) and | |
(not($du2-date) or | |
(not(translate($du2-date, '0123456789YMD', '')) and | |
not(substring-after($du2-date, 'D')) and | |
(contains($du2-date, 'D') or | |
(not(substring-after($du2-date, 'M')) and | |
(contains($du2-date, 'M') or | |
not(substring-after($du2-date, 'Y'))))))) and | |
(not($du2-time) or | |
(not(translate($du2-time, '0123456789HMS.', '')) and | |
not(substring-after($du2-time, 'S')) and | |
(contains($du2-time, 'S') or | |
not(substring-after($du2-time, 'M')) and | |
(contains($du2-time, 'M') or | |
not(substring-after($du2-time, 'Y'))))))"> | |
<xsl:variable name="du1y-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before($du1-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1m-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du1-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1d-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-date, 'M')"><xsl:value-of select="substring-before(substring-after($du1-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du1-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du1-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1h-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before($du1-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1min-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before(substring-after($du1-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du1s-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du1-time, 'M')"><xsl:value-of select="substring-before(substring-after($du1-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du1-time, 'H')"><xsl:value-of select="substring-before(substring-after($du1-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du1-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult1" select="($du1-neg * -2) + 1" /> | |
<xsl:variable name="du1y" select="$du1y-str * $mult1" /> | |
<xsl:variable name="du1m" select="$du1m-str * $mult1" /> | |
<xsl:variable name="du1d" select="$du1d-str * $mult1" /> | |
<xsl:variable name="du1h" select="$du1h-str * $mult1" /> | |
<xsl:variable name="du1min" select="$du1min-str * $mult1" /> | |
<xsl:variable name="du1s" select="$du1s-str * $mult1" /> | |
<xsl:variable name="du2y-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before($du2-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2m-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du2-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2d-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-date, 'M')"><xsl:value-of select="substring-before(substring-after($du2-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du2-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du2-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2h-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before($du2-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2min-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before(substring-after($du2-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du2s-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du2-time, 'M')"><xsl:value-of select="substring-before(substring-after($du2-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du2-time, 'H')"><xsl:value-of select="substring-before(substring-after($du2-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du2-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult2" select="($du2-neg * -2) + 1" /> | |
<xsl:variable name="du2y" select="$du2y-str * $mult2" /> | |
<xsl:variable name="du2m" select="$du2m-str * $mult2" /> | |
<xsl:variable name="du2d" select="$du2d-str * $mult2" /> | |
<xsl:variable name="du2h" select="$du2h-str * $mult2" /> | |
<xsl:variable name="du2min" select="$du2min-str * $mult2" /> | |
<xsl:variable name="du2s" select="$du2s-str * $mult2" /> | |
<xsl:variable name="min-s" select="60" /> | |
<xsl:variable name="hour-s" select="60 * 60" /> | |
<xsl:variable name="day-s" select="60 * 60 * 24" /> | |
<xsl:variable name="seconds" select="($du1s + $du2s) + | |
(($du1min + $du2min) * $min-s) + | |
(($du1h + $du2h) * $hour-s) + | |
(($du1d + $du2d) * $day-s)" /> | |
<xsl:variable name="months" select="($du1m + $du2m) + | |
(($du1y + $du2y) * 12)" /> | |
<xsl:choose> | |
<xsl:when test="($months * $seconds) < 0" /> | |
<xsl:when test="$months or $seconds"> | |
<xsl:if test="$months < 0 or $seconds < 0">-</xsl:if> | |
<xsl:text>P</xsl:text> | |
<xsl:variable name="m" select="$months * ((($months >= 0) * 2) - 1)" /> | |
<xsl:variable name="years" select="floor($m div 12)" /> | |
<xsl:variable name="mnths" select="$m - ($years * 12)" /> | |
<xsl:variable name="s" select="$seconds * ((($seconds >= 0) * 2) - 1)" /> | |
<xsl:variable name="days" select="floor($s div $day-s)" /> | |
<xsl:variable name="hours" select="floor(($s - ($days * $day-s)) div $hour-s)" /> | |
<xsl:variable name="mins" select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)" /> | |
<xsl:variable name="secs" select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)" /> | |
<xsl:if test="$years"> | |
<xsl:value-of select="$years" /> | |
<xsl:text>Y</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mnths"> | |
<xsl:value-of select="$mnths" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$days"> | |
<xsl:value-of select="$days" /> | |
<xsl:text>D</xsl:text> | |
</xsl:if> | |
<xsl:if test="$hours or $mins or $secs">T</xsl:if> | |
<xsl:if test="$hours"> | |
<xsl:value-of select="$hours" /> | |
<xsl:text>H</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mins"> | |
<xsl:value-of select="$mins" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$secs"> | |
<xsl:value-of select="$secs" /> | |
<xsl:text>S</xsl:text> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>P</xsl:otherwise> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:value-of select="$duration" /> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="2" module="date" status="implemented"> | |
<exslt:name>add-duration</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add-duration</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Made it illegal to have an addition result in positive (years and) months and negative (days, hours, minutes and) seconds, or vice versa.</li> | |
<li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.2.1"> | |
<exslt:version>2.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.2.2"> | |
<exslt:version>2.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added libxslt implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:add-duration</code> function returns the duration resulting from adding two durations together. | |
</p> | |
<p> | |
Both arguments are strings in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If either argument is not in this format, the function returns an empty string (<code>''</code>). | |
</p> | |
<p> | |
The return value is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p> | |
<p> | |
The durations can usually be added by summing the numbers given for each of the components in the durations. However, if the durations are differently signed, then this sometimes results in durations that are impossible to express in this syntax (e.g. <code>'P1M'</code> + <code>'-P1D'</code>). In these cases, the function returns an empty string (<code>''</code>). | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="string" /> | |
<exslt:arg name="duration1" type="string" | |
optional="no" /> | |
<exslt:arg name="duration2" type="string" | |
optional="no" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.add-duration.function.xsl" language="exslt:exslt" | |
version="2" /> | |
<exslt:implementation src="date.add-duration.template.xsl" language="exslt:xslt" | |
version="2" /> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add-duration</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add-duration</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add-duration.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="date.add-duration.function.xsl"/> | |
<import href="date.add-duration.template.xsl"/> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<date:month-lengths> | |
<date:month>31</date:month> | |
<date:month>28</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
</date:month-lengths> | |
<func:function name="date:add"> | |
<xsl:param name="date-time" /> | |
<xsl:param name="duration" /> | |
<xsl:variable name="dt-neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$dt-neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="new-dt"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:variable name="du-neg" select="starts-with($duration, '-')" /> | |
<xsl:variable name="du"> | |
<xsl:choose> | |
<xsl:when test="$du-neg"><xsl:value-of select="substring($duration, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:if test="starts-with($du, 'P') and | |
not(translate($du, '0123456789PYMDTHS.', ''))"> | |
<xsl:variable name="du-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du, 'T')"><xsl:value-of select="substring-before(substring($du, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du-time"> | |
<xsl:if test="contains($du, 'T')"><xsl:value-of select="substring-after($du, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:if test="(not($du-date) or | |
(not(translate($du-date, '0123456789YMD', '')) and | |
not(substring-after($du-date, 'D')) and | |
(contains($du-date, 'D') or | |
(not(substring-after($du-date, 'M')) and | |
(contains($du-date, 'M') or | |
not(substring-after($du-date, 'Y'))))))) and | |
(not($du-time) or | |
(not(translate($du-time, '0123456789HMS.', '')) and | |
not(substring-after($du-time, 'S')) and | |
(contains($du-time, 'S') or | |
not(substring-after($du-time, 'M')) and | |
(contains($du-time, 'M') or | |
not(substring-after($du-time, 'Y'))))))"> | |
<xsl:variable name="duy-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before($du-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dum-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dud-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'M')"><xsl:value-of select="substring-before(substring-after($du-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="duh-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before($du-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dumin-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before(substring-after($du-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dus-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'M')"><xsl:value-of select="substring-before(substring-after($du-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before(substring-after($du-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult" select="($du-neg * -2) + 1" /> | |
<xsl:variable name="duy" select="$duy-str * $mult" /> | |
<xsl:variable name="dum" select="$dum-str * $mult" /> | |
<xsl:variable name="dud" select="$dud-str * $mult" /> | |
<xsl:variable name="duh" select="$duh-str * $mult" /> | |
<xsl:variable name="dumin" select="$dumin-str * $mult" /> | |
<xsl:variable name="dus" select="$dus-str * $mult" /> | |
<xsl:variable name="year" select="substring($dt, 1, 4) * (($dt-neg * -2) + 1)" /> | |
<xsl:choose> | |
<xsl:when test="$year and | |
string($duy) = 'NaN' or | |
string($dum) = 'NaN' or | |
string($dud) = 'NaN' or | |
string($duh) = 'NaN' or | |
string($dumin) = 'NaN' or | |
string($dus) = 'NaN'" /> | |
<xsl:when test="$dt-length > 4 or | |
$dum or $dud or $duh or $dumin or $dus"> | |
<xsl:variable name="month"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 4"> | |
<xsl:if test="substring($dt, 5, 1) = '-'"> | |
<xsl:value-of select="substring($dt, 6, 2)" /> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>1</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="not($month) or $month > 12" /> | |
<xsl:when test="$dt-length > 7 or | |
$dud or $duh or $dumin or $dus"> | |
<xsl:variable name="day"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 7"> | |
<xsl:if test="substring($dt, 8, 1) = '-'"> | |
<xsl:value-of select="substring($dt, 9, 2)" /> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>1</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="not($day) or $day > 31" /> | |
<xsl:when test="$dt-length > 10 or | |
$duh or $dumin or $dus"> | |
<xsl:if test="$dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 17, 1) = ':')"> | |
<xsl:variable name="hour"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 12, 2)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="minute"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 15, 2)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="second"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 18)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:if test="$hour <= 23 and $minute <= 59 and $second <= 60"> | |
<xsl:variable name="new-second" select="$second + $dus" /> | |
<xsl:variable name="new-minute" select="$minute + $dumin + floor($new-second div 60)" /> | |
<xsl:variable name="new-hour" select="$hour + $duh + floor($new-minute div 60)" /> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + $duy + floor(($new-month - 1) div 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="day" select="$day" /> | |
<xsl:with-param name="days" select="$dud + floor($new-hour div 24)" /> | |
</xsl:call-template> | |
<xsl:text>T</xsl:text> | |
<xsl:value-of select="format-number(($new-hour + 24) mod 24, '00')" /> | |
<xsl:text>:</xsl:text> | |
<xsl:value-of select="format-number($new-minute mod 60, '00')" /> | |
<xsl:text>:</xsl:text> | |
<xsl:if test="$new-second mod 60 < 10">0</xsl:if> | |
<xsl:value-of select="$new-second mod 60" /> | |
<xsl:value-of select="$timezone" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + $duy + floor(($new-month - 1) div 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="day" select="$day" /> | |
<xsl:with-param name="days" select="$dud" /> | |
</xsl:call-template> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:value-of select="format-number($year + $duy + floor(($new-month - 1) div 12), '0000')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="format-number($year + $duy, '0000')" /> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="string-length($date-time) > 10"> | |
<func:result select="$new-dt" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<func:result select="substring($new-dt, 1, string-length($date-time))" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</func:function> | |
<xsl:template name="date:_add-days"> | |
<xsl:param name="year" /> | |
<xsl:param name="month" /> | |
<xsl:param name="day" /> | |
<xsl:param name="days" /> | |
<xsl:param name="new-day" select="'NaN'" /> | |
<xsl:variable name="leap" select="(not($year mod 4) and $year mod 100) or not($year mod 400)" /> | |
<xsl:variable name="month-days" select="document('')/*/date:month-lengths/date:month" /> | |
<xsl:variable name="days-in-month"> | |
<xsl:choose> | |
<xsl:when test="$month = 2 and $leap"> | |
<xsl:value-of select="$month-days[number($month)] + 1" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$month-days[number($month)]" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$new-day = 'NaN'"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year" /> | |
<xsl:with-param name="month" select="$month" /> | |
<xsl:with-param name="new-day"> | |
<xsl:choose> | |
<xsl:when test="$day > $days-in-month"> | |
<xsl:value-of select="$days-in-month + $days" /> | |
</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$day + $days" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:choose> | |
<xsl:when test="$new-day < 1"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year - ($month = 1)" /> | |
<xsl:with-param name="month"> | |
<xsl:choose> | |
<xsl:when test="$month = 1">12</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$month - 1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="new-day"> | |
<xsl:variable name="days-in-new-month"> | |
<xsl:choose> | |
<xsl:when test="$leap and $month = 3">29</xsl:when> | |
<xsl:when test="$month = 1">31</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$month-days[$month - 1]" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:value-of select="$new-day + $days-in-new-month" /> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:when test="$new-day > $days-in-month"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + ($month = 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:choose> | |
<xsl:when test="$month = 12">1</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$month + 1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="new-day" select="$new-day - $days-in-month" /> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="format-number($year, '0000')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:value-of select="format-number($month, '00')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:value-of select="format-number($new-day, '00')" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:add - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/add">add</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>2<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.add.xml">date.add.xml</a><br/><b>Function Package: </b><a href="date.add.zip">date.add.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:add</b>(<var>string</var>, <var>string</var>)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:add</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" /> | |
<xsl:with-param name="duration" select="<var>string</var>" /> | |
</xsl:call-template></pre><div><p> | |
The <code>date:add</code> function returns the date/time resulting from adding a duration to a date/time. | |
</p><p> | |
The first argument must be right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gYearMonth" class="offsite"><code>xs:gYearMonth</code></a> (<code><var>CCYY</var>-<var>MM</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gYear" class="offsite"><code>xs:gYear</code></a> (<code><var>CCYY</var></code>) | |
</li></ul><p> | |
The second argument is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p> | |
The return value is a right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and listed above. This value is calculated using the algorithm described in [<a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes" class="offsite">Appendix E Adding durations to dateTimes</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:add</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://4Suite.org">4XSLT, from 4Suite.</a></td><td>0.12.0a3</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>2</td></tr></table><p> | |
The following implementations of <code>date:add</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.add.function.xsl.html">EXSLT Function</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.add.function.xsl">date.add.function.xsl</a></td></tr><tr><td class="rowhead"><a href="date.add.template.xsl.html">XSLT Template</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.add.template.xsl">date.add.template.xsl</a></td></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Previous Version: </b><a href="date.add.1.html">date.add.1.html</a></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">2</td><td style="width: 5em;">2001-06-10</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Changed the behaviour when the specificity of the date/time and duration don't match to bring it into line with the XML Schemas Recommendation.</li><li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.1</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.2</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added 4XSLT and libxslt implementation to the list.</dc:description></p></td></tr><tr><td class="rowhead">2.3</td><td style="width: 5em;">2002-11-12</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Updated 4XSLT version to 0.12.0a3.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/add/date.add.html">http://www.exslt.org/date/functions/add/date.add.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<date:month-lengths> | |
<date:month>31</date:month> | |
<date:month>28</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
</date:month-lengths> | |
<xsl:template name="date:add"> | |
<xsl:param name="date-time" /> | |
<xsl:param name="duration" /> | |
<xsl:variable name="dt-neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$dt-neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="new-dt"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:variable name="du-neg" select="starts-with($duration, '-')" /> | |
<xsl:variable name="du"> | |
<xsl:choose> | |
<xsl:when test="$du-neg"><xsl:value-of select="substring($duration, 2)" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$duration" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:if test="starts-with($du, 'P') and | |
not(translate($du, '0123456789PYMDTHS.', ''))"> | |
<xsl:variable name="du-date"> | |
<xsl:choose> | |
<xsl:when test="contains($du, 'T')"><xsl:value-of select="substring-before(substring($du, 2), 'T')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring($du, 2)" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="du-time"> | |
<xsl:if test="contains($du, 'T')"><xsl:value-of select="substring-after($du, 'T')" /></xsl:if> | |
</xsl:variable> | |
<xsl:if test="(not($du-date) or | |
(not(translate($du-date, '0123456789YMD', '')) and | |
not(substring-after($du-date, 'D')) and | |
(contains($du-date, 'D') or | |
(not(substring-after($du-date, 'M')) and | |
(contains($du-date, 'M') or | |
not(substring-after($du-date, 'Y'))))))) and | |
(not($du-time) or | |
(not(translate($du-time, '0123456789HMS.', '')) and | |
not(substring-after($du-time, 'S')) and | |
(contains($du-time, 'S') or | |
not(substring-after($du-time, 'M')) and | |
(contains($du-time, 'M') or | |
not(substring-after($du-time, 'Y'))))))"> | |
<xsl:variable name="duy-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before($du-date, 'Y')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dum-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du-date, 'Y'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-date, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dud-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'D')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-date, 'M')"><xsl:value-of select="substring-before(substring-after($du-date, 'M'), 'D')" /></xsl:when> | |
<xsl:when test="contains($du-date, 'Y')"><xsl:value-of select="substring-before(substring-after($du-date, 'Y'), 'D')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-date, 'D')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="duh-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before($du-time, 'H')" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dumin-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'M')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before(substring-after($du-time, 'H'), 'M')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-time, 'M')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dus-str"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'S')"> | |
<xsl:choose> | |
<xsl:when test="contains($du-time, 'M')"><xsl:value-of select="substring-before(substring-after($du-time, 'M'), 'S')" /></xsl:when> | |
<xsl:when test="contains($du-time, 'H')"><xsl:value-of select="substring-before(substring-after($du-time, 'H'), 'S')" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="substring-before($du-time, 'S')" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="mult" select="($du-neg * -2) + 1" /> | |
<xsl:variable name="duy" select="$duy-str * $mult" /> | |
<xsl:variable name="dum" select="$dum-str * $mult" /> | |
<xsl:variable name="dud" select="$dud-str * $mult" /> | |
<xsl:variable name="duh" select="$duh-str * $mult" /> | |
<xsl:variable name="dumin" select="$dumin-str * $mult" /> | |
<xsl:variable name="dus" select="$dus-str * $mult" /> | |
<xsl:variable name="year" select="substring($dt, 1, 4) * (($dt-neg * -2) + 1)" /> | |
<xsl:choose> | |
<xsl:when test="$year and | |
string($duy) = 'NaN' or | |
string($dum) = 'NaN' or | |
string($dud) = 'NaN' or | |
string($duh) = 'NaN' or | |
string($dumin) = 'NaN' or | |
string($dus) = 'NaN'" /> | |
<xsl:when test="$dt-length > 4 or | |
$dum or $dud or $duh or $dumin or $dus"> | |
<xsl:variable name="month"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 4"> | |
<xsl:if test="substring($dt, 5, 1) = '-'"> | |
<xsl:value-of select="substring($dt, 6, 2)" /> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>1</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="not($month) or $month > 12" /> | |
<xsl:when test="$dt-length > 7 or | |
$dud or $duh or $dumin or $dus"> | |
<xsl:variable name="day"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 7"> | |
<xsl:if test="substring($dt, 8, 1) = '-'"> | |
<xsl:value-of select="substring($dt, 9, 2)" /> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise>1</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="not($day) or $day > 31" /> | |
<xsl:when test="$dt-length > 10 or | |
$duh or $dumin or $dus"> | |
<xsl:if test="$dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 17, 1) = ':')"> | |
<xsl:variable name="hour"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 12, 2)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="minute"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 15, 2)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="second"> | |
<xsl:choose> | |
<xsl:when test="$dt-length > 10"><xsl:value-of select="substring($dt, 18)" /></xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:if test="$hour <= 23 and $minute <= 59 and $second <= 60"> | |
<xsl:variable name="new-second" select="$second + $dus" /> | |
<xsl:variable name="new-minute" select="$minute + $dumin + floor($new-second div 60)" /> | |
<xsl:variable name="new-hour" select="$hour + $duh + floor($new-minute div 60)" /> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + $duy + floor(($new-month - 1) div 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="day" select="$day" /> | |
<xsl:with-param name="days" select="$dud + floor($new-hour div 24)" /> | |
</xsl:call-template> | |
<xsl:text>T</xsl:text> | |
<xsl:value-of select="format-number(($new-hour + 24) mod 24, '00')" /> | |
<xsl:text>:</xsl:text> | |
<xsl:value-of select="format-number($new-minute mod 60, '00')" /> | |
<xsl:text>:</xsl:text> | |
<xsl:if test="$new-second mod 60 < 10">0</xsl:if> | |
<xsl:value-of select="$new-second mod 60" /> | |
<xsl:value-of select="$timezone" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + $duy + floor(($new-month - 1) div 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="day" select="$day" /> | |
<xsl:with-param name="days" select="$dud" /> | |
</xsl:call-template> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="new-month" select="$month + $dum" /> | |
<xsl:value-of select="format-number($year + $duy + floor(($new-month - 1) div 12), '0000')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:variable name="m"> | |
<xsl:choose> | |
<xsl:when test="$new-month < 1"><xsl:value-of select="$new-month + 12" /></xsl:when> | |
<xsl:otherwise><xsl:value-of select="$new-month" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$m mod 12"> | |
<xsl:value-of select="format-number($m mod 12, '00')" /> | |
</xsl:when> | |
<xsl:otherwise>12</xsl:otherwise> | |
</xsl:choose> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="format-number($year + $duy, '0000')" /> | |
<xsl:value-of select="$timezone" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="string-length($date-time) > 10"> | |
<xsl:value-of select="$new-dt" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="substring($new-dt, 1, string-length($date-time))" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="date:_add-days"> | |
<xsl:param name="year" /> | |
<xsl:param name="month" /> | |
<xsl:param name="day" /> | |
<xsl:param name="days" /> | |
<xsl:param name="new-day" select="'NaN'" /> | |
<xsl:variable name="leap" select="(not($year mod 4) and $year mod 100) or not($year mod 400)" /> | |
<xsl:variable name="month-days" select="document('')/*/date:month-lengths/date:month" /> | |
<xsl:variable name="days-in-month"> | |
<xsl:choose> | |
<xsl:when test="$month = 2 and $leap"> | |
<xsl:value-of select="$month-days[number($month)] + 1" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$month-days[number($month)]" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$new-day = 'NaN'"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year" /> | |
<xsl:with-param name="month" select="$month" /> | |
<xsl:with-param name="new-day"> | |
<xsl:choose> | |
<xsl:when test="$day > $days-in-month"> | |
<xsl:value-of select="$days-in-month + $days" /> | |
</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$day + $days" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:choose> | |
<xsl:when test="$new-day < 1"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year - ($month = 1)" /> | |
<xsl:with-param name="month"> | |
<xsl:choose> | |
<xsl:when test="$month = 1">12</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$month - 1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="new-day"> | |
<xsl:variable name="days-in-new-month"> | |
<xsl:choose> | |
<xsl:when test="$leap and $month = 3">29</xsl:when> | |
<xsl:when test="$month = 1">31</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$month-days[$month - 1]" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:value-of select="$new-day + $days-in-new-month" /> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:when test="$new-day > $days-in-month"> | |
<xsl:call-template name="date:_add-days"> | |
<xsl:with-param name="year" select="$year + ($month = 12)" /> | |
<xsl:with-param name="month"> | |
<xsl:choose> | |
<xsl:when test="$month = 12">1</xsl:when> | |
<xsl:otherwise><xsl:value-of select="$month + 1" /></xsl:otherwise> | |
</xsl:choose> | |
</xsl:with-param> | |
<xsl:with-param name="new-day" select="$new-day - $days-in-month" /> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="format-number($year, '0000')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:value-of select="format-number($month, '00')" /> | |
<xsl:text>-</xsl:text> | |
<xsl:value-of select="format-number($new-day, '00')" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="2" module="date" status="implemented"> | |
<exslt:name>add</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-10</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Changed the behaviour when the specificity of the date/time and duration don't match to bring it into line with the XML Schemas Recommendation.</li> | |
<li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.2.1"> | |
<exslt:version>2.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.2.2"> | |
<exslt:version>2.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added 4XSLT and libxslt implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.2.3"> | |
<exslt:version>2.3</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-11-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Updated 4XSLT version to 0.12.0a3.</dc:description> | |
</rdf:Description> | |
</exslt:revision></rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:add</code> function returns the date/time resulting from adding a duration to a date/time. | |
</p> | |
<p> | |
The first argument must be right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p> | |
<ul> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#gYearMonth" class="offsite"><code>xs:gYearMonth</code></a> (<code><var>CCYY</var>-<var>MM</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#gYear" class="offsite"><code>xs:gYear</code></a> (<code><var>CCYY</var></code>) | |
</li> | |
</ul> | |
<p> | |
The second argument is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p> | |
<p> | |
The return value is a right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and listed above. This value is calculated using the algorithm described in [<a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes" class="offsite">Appendix E Adding durations to dateTimes</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="string" /> | |
<exslt:arg name="date-time" type="string" | |
optional="no" /> | |
<exslt:arg name="duration" type="string" | |
optional="no" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="4XSLT, from 4Suite." | |
vendor-url="http://4Suite.org" | |
vendor-version="0.12.0a3" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.add.function.xsl" language="exslt:exslt" | |
version="2" /> | |
<exslt:implementation src="date.add.template.xsl" language="exslt:xslt" | |
version="2" /> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>add</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:add.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="date.add.function.xsl"/> | |
<import href="date.add.template.xsl"/> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date-format - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/elements/date-format">date-format</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>1<br/><b>Status: </b>new<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.date-format.xml">date.date-format.xml</a><br/><b>Element Package: </b><a href="date.date-format.zip">date.date-format.zip</a></p><h4>Element Syntax</h4><pre><date:date-format | |
name = <var>qname</var> | |
calendar = "gregorian" | <var>qname-but-not-ncname</var> | |
lang = <var>language</var> | |
first-day-of-week = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday" | <var>string</var> /></pre><div><p> | |
The <code>date:date-format</code> element declares a <code>date format</code>, which controls the interpretation of a format pattern used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions. | |
</p><p> | |
If there is a <code>name</code> attribute, then the element declares a named date format; otherwise, it declares the default date format. The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>, which is expanded as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]. It is an error to declare either the default date format or a date format with a given name more than once (even with different import precedence), unless it is declared every time with the same value for all attributes (taking into account any default values). | |
</p><p> | |
The <code>calendar</code> attribute specifies the calendar used to interpret format strings using the date format. The value must be a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> does not have a prefix, then it identifies calendar specified in this document and must be <code>gregorian</code>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> has a prefix, then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> is expanded into an expanded-name as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]; the expanded-name identifies the calendar; the interpretation of the format pattern used in the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions in this case is not specified by this document. If the processor does not support the calendar used by the date format used in these functions, the result of these functions is an empty string (<code>''</code>). | |
</p><p> | |
If there is no <code>calendar</code> attribute or it has the value <code>gregorian</code>, then the date/time being processed is interpreted as using the Gregorian calendar, with the same assumptions as made by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.util.GregorianCalendar.html" class="offsite">GregorianCalendar</a> class. If this date format is used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> or <a href="/date/functions/parse-date"><code>date:parse-date</code></a> function, then the format pattern strings that they use must be in the syntax specified by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. The format pattern string is interpreted as described for the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. | |
</p><p> | |
The <code>lang</code> attribute specifies the language of the strings used in formatting the date; it has the same range of values as xml:lang [<a href="http://www.w3.org/TR/1998/REC-xml-19980210" class="offsite">XML</a>]; if no <code>lang</code> value is specified or if the processor does not support the specified language, the language should be determined from the system environment. | |
</p><p> | |
The <code>first-day-in-week</code> attribute specifies the day that's used as the first day of the week for calculating numbers of the week in month, week in year and day in week. If the calendar is Gregorian, then it must be one of the strings <code>sunday</code>, <code>monday</code>, <code>tuesday</code>, <code>wednesday</code>, <code>thursday</code>, <code>friday</code> or <code>saturday</code>. Otherwise the values are restricted based on the calendar being used for the date format. | |
</p></div><p> | |
An implementation of this extension | |
element | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p>No XSLT processors that we know of have built-in support for <code>date:date-format</code>.</p><p>There are currently no third-party implementations of <code>date:date-format</code>.</p><h2>Change History</h2><p><b>Submitted: </b>2001-05-13<br/><b>Creator: </b><a href="mailto:[email protected]">Jeni Tennison</a>(<a href="http://www.jenitennison.com/">http://www.jenitennison.com/</a>)</p><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Defines a date format used to interpret a format pattern within <a href="/date/functions/format-date"><code>format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a>. | |
</dc:description></p></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/elements/date-format/date.date-format.html">http://www.exslt.org/date/elements/date-format/date.date-format.html</a> last modified 2001-05-13</p></div></body></html> |
<?xml version="1.0"?> | |
<exslt:element xmlns:exslt="http://exslt.org/documentation" | |
version="1" module="date" status="new"> | |
<exslt:name>date-format</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-format"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>date-format</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-format.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-05-13</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Defines a date format used to interpret a format pattern within <a href="/date/functions/format-date"><code>format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a>. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:date-format</code> element declares a <code>date format</code>, which controls the interpretation of a format pattern used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions. | |
</p> | |
<p> | |
If there is a <code>name</code> attribute, then the element declares a named date format; otherwise, it declares the default date format. The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>, which is expanded as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]. It is an error to declare either the default date format or a date format with a given name more than once (even with different import precedence), unless it is declared every time with the same value for all attributes (taking into account any default values). | |
</p> | |
<p> | |
The <code>calendar</code> attribute specifies the calendar used to interpret format strings using the date format. The value must be a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> does not have a prefix, then it identifies calendar specified in this document and must be <code>gregorian</code>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> has a prefix, then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> is expanded into an expanded-name as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]; the expanded-name identifies the calendar; the interpretation of the format pattern used in the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions in this case is not specified by this document. If the processor does not support the calendar used by the date format used in these functions, the result of these functions is an empty string (<code>''</code>). | |
</p> | |
<p> | |
If there is no <code>calendar</code> attribute or it has the value <code>gregorian</code>, then the date/time being processed is interpreted as using the Gregorian calendar, with the same assumptions as made by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.util.GregorianCalendar.html" class="offsite">GregorianCalendar</a> class. If this date format is used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> or <a href="/date/functions/parse-date"><code>date:parse-date</code></a> function, then the format pattern strings that they use must be in the syntax specified by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. The format pattern string is interpreted as described for the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. | |
</p> | |
<p> | |
The <code>lang</code> attribute specifies the language of the strings used in formatting the date; it has the same range of values as xml:lang [<a href="http://www.w3.org/TR/1998/REC-xml-19980210" class="offsite">XML</a>]; if no <code>lang</code> value is specified or if the processor does not support the specified language, the language should be determined from the system environment. | |
</p> | |
<p> | |
The <code>first-day-in-week</code> attribute specifies the day that's used as the first day of the week for calculating numbers of the week in month, week in year and day in week. If the calendar is Gregorian, then it must be one of the strings <code>sunday</code>, <code>monday</code>, <code>tuesday</code>, <code>wednesday</code>, <code>thursday</code>, <code>friday</code> or <code>saturday</code>. Otherwise the values are restricted based on the calendar being used for the date format. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<xs:attribute name="name" type="xsl:qname" /> | |
<xs:attribute name="calendar" required="no"> | |
<xs:simpleType> | |
<xs:union memberTypes="xsl:qname-but-not-ncname"> | |
<xs:simpleType> | |
<xs:restriction base="xs:NMTOKEN"> | |
<xs:enumeration value="gregorian" /> | |
</xs:restriction> | |
</xs:simpleType> | |
</xs:union> | |
</xs:simpleType> | |
</xs:attribute> | |
<xs:attribute name="lang" type="xs:language" /> | |
<xs:attribute name="first-day-of-week"> | |
<xs:simpleType> | |
<xs:union memberTypes="xsl:string"> | |
<xs:restriction base="xs:NMTOKEN"> | |
<xs:enumeration value="sunday" /> | |
<xs:enumeration value="monday" /> | |
<xs:enumeration value="tuesday" /> | |
<xs:enumeration value="wednesday" /> | |
<xs:enumeration value="thursday" /> | |
<xs:enumeration value="friday" /> | |
<xs:enumeration value="saturday" /> | |
</xs:restriction> | |
</xs:union> | |
</xs:simpleType> | |
</xs:attribute> | |
</exslt:definition> | |
<exslt:implementations /> | |
<exslt:use-cases /> | |
</exslt:element> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date-time - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/date-time">date-time</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>1<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.date-time.xml">date.date-time.xml</a><br/><b>Function Package: </b><a href="date.date-time.zip">date.date-time.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:date-time</b>()</pre><div><p> | |
The <code>date:date-time</code> 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 <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
The date/time string format must include a time zone, either a <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:date-time</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a></td><td>6.4.2</td><td>1</td></tr><tr><td class="rowhead"><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a></td><td>2.4.D1</td><td>1</td></tr><tr><td class="rowhead"><a href="http://4Suite.org">4XSLT, from 4Suite.</a></td><td>0.12.0a3</td><td>1</td></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>1</td></tr></table><p> | |
The following implementations of <code>date:date-time</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>1</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>1</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Submitted: </b>2001-05-12<br/><b>Creator: </b><a href="mailto:[email protected]">Jeni Tennison</a>(<a href="http://www.jenitennison.com/">http://www.jenitennison.com/</a>)</p><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Returns the current date and time. | |
</dc:description></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">1.1</td><td style="width: 5em;">2001-06-11</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Added Javascript implementation. | |
</dc:description></p></td></tr><tr><td class="rowhead">1.2</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">1.3</td><td style="width: 5em;">2001-07-20</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description></p></td></tr><tr><td class="rowhead">1.4</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description></p></td></tr><tr><td class="rowhead">1.5</td><td style="width: 5em;">2002-11-12</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Updated 4XSLT version to 0.12.0a3.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/date-time/date.date-time.html">http://www.exslt.org/date/functions/date-time/date.date-time.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="1" module="date" status="implemented"> | |
<exslt:name>date-time</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date-time</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-05-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Returns the current date and time. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1.1"> | |
<exslt:version>1.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Added Javascript implementation. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1.2"> | |
<exslt:version>1.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1.3"> | |
<exslt:version>1.3</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-07-20</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1.4"> | |
<exslt:version>1.4</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.1.5"> | |
<exslt:version>1.5</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-11-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Updated 4XSLT version to 0.12.0a3.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:date-time</code> 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 <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p> | |
<p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p> | |
<p> | |
The date/time string format must include a time zone, either a <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="string" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="1" | |
vendor="SAXON from Michael Kay" | |
vendor-url="http://users.iclway.co.uk/mhkay/saxon/index.html" | |
vendor-version="6.4.2" /> | |
<exslt:vendor-implementation | |
version="1" | |
vendor="Xalan-J from Apache" | |
vendor-url="http://xml.apache.org/xalan-j" | |
vendor-version="2.4.D1" /> | |
<exslt:vendor-implementation | |
version="1" | |
vendor="4XSLT, from 4Suite." | |
vendor-url="http://4Suite.org" | |
vendor-version="0.12.0a3" /> | |
<exslt:vendor-implementation | |
version="1" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="1"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>date-time</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="1"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>date-time</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date-time.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<func:function name="date:date"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="date"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:if test="number(substring($dt, 1, 4)) and | |
substring($dt, 5, 1) = '-' and | |
substring($dt, 6, 2) <= 12 and | |
substring($dt, 8, 1) = '-' and | |
substring($dt, 9, 2) <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:value-of select="substring($dt, 1, 10)" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="string($date)"> | |
<xsl:choose> | |
<xsl:when test="$neg"> | |
<func:result select="concat('-', $date, $timezone)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<func:result select="concat($date, $timezone)" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:when> | |
<xsl:otherwise> | |
<func:result /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</func:function> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/date">date</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>2<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.date.xml">date.date.xml</a><br/><b>Function Package: </b><a href="date.date.zip">date.date.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:date</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:date</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:date</code> 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 <code>date:date-time</code> is used as a default argument. | |
</p><p> | |
The date/time string specified as an argument must be a string in the format defined as the lexical representation of either <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] or <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If the argument is not in either of these formats, <code>date:date</code> returns an empty string (<code>''</code>). | |
</p><p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
The date is returned as a string with a lexical representation as defined for <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p class="note"> | |
The date format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
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 <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. If an argument is specified and it does not specify a time zone, then the date string format must not include a time zone. | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:date</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a></td><td>6.4.2</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a></td><td>2.4.D1</td><td>2</td></tr><tr><td class="rowhead"><a href="http://4Suite.org">4XSLT, from 4Suite.</a></td><td>0.12.0a3</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>2</td></tr></table><p> | |
The following implementations of <code>date:date</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.date.function.xsl.html">EXSLT Function</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.date.function.xsl">date.date.function.xsl</a></td></tr><tr><td class="rowhead"><a href="date.date.template.xsl.html">XSLT Template</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.date.template.xsl">date.date.template.xsl</a></td></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Previous Version: </b><a href="date.date.1.html">date.date.1.html</a></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">2</td><td style="width: 5em;">2001-06-10</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Added <code>xs:date</code> as a valid argument format.</li><li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.1</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.2</td><td style="width: 5em;">2001-07-20</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description></p></td></tr><tr><td class="rowhead">2.3</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description></p></td></tr><tr><td class="rowhead">2.4</td><td style="width: 5em;">2002-11-12</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Updated 4XSLT version to 0.12.0a3.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/date/date.date.html">http://www.exslt.org/date/functions/date/date.date.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<xsl:template name="date:date"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="date"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:if test="number(substring($dt, 1, 4)) and | |
substring($dt, 5, 1) = '-' and | |
substring($dt, 6, 2) <= 12 and | |
substring($dt, 8, 1) = '-' and | |
substring($dt, 9, 2) <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:value-of select="substring($dt, 1, 10)" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:if test="string($date)"> | |
<xsl:if test="$neg">-</xsl:if> | |
<xsl:value-of select="$date" /> | |
<xsl:value-of select="$timezone" /> | |
</xsl:if> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="2" module="date" status="implemented"> | |
<exslt:name>date</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-10</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Added <code>xs:date</code> as a valid argument format.</li> | |
<li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.2.1"> | |
<exslt:version>2.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.2.2"> | |
<exslt:version>2.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-07-20</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.2.3"> | |
<exslt:version>2.3</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.2.4"> | |
<exslt:version>2.4</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-11-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Updated 4XSLT version to 0.12.0a3.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:date</code> 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 <code>date:date-time</code> is used as a default argument. | |
</p> | |
<p> | |
The date/time string specified as an argument must be a string in the format defined as the lexical representation of either <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] or <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If the argument is not in either of these formats, <code>date:date</code> returns an empty string (<code>''</code>). | |
</p> | |
<p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p> | |
<p> | |
The date is returned as a string with a lexical representation as defined for <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p> | |
<p class="note"> | |
The date format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p> | |
<p> | |
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 <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. If an argument is specified and it does not specify a time zone, then the date string format must not include a time zone. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="string" /> | |
<exslt:arg name="date-time" type="string" | |
optional="yes" default="date:date-time()" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="SAXON from Michael Kay" | |
vendor-url="http://users.iclway.co.uk/mhkay/saxon/index.html" | |
vendor-version="6.4.2" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="Xalan-J from Apache" | |
vendor-url="http://xml.apache.org/xalan-j" | |
vendor-version="2.4.D1" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="4XSLT, from 4Suite." | |
vendor-url="http://4Suite.org" | |
vendor-version="0.12.0a3" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.date.function.xsl" language="exslt:exslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.date.template.xsl" language="exslt:xslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:date.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="date.date.function.xsl"/> | |
<import href="date.date.template.xsl"/> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<date:month-lengths> | |
<date:month>31</date:month> | |
<date:month>28</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
</date:month-lengths> | |
<date:days> | |
<date:day abbr="Sun">Sunday</date:day> | |
<date:day abbr="Mon">Monday</date:day> | |
<date:day abbr="Tue">Tuesday</date:day> | |
<date:day abbr="Wed">Wednesday</date:day> | |
<date:day abbr="Thu">Thursday</date:day> | |
<date:day abbr="Fri">Friday</date:day> | |
<date:day abbr="Sat">Saturday</date:day> | |
</date:days> | |
<func:function name="date:day-abbreviation"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="day-of-week"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:variable name="year" select="substring($dt, 1, 4)" /> | |
<xsl:variable name="leap" select="(not($year mod 4) and $year mod 100) or not($year mod 400)" /> | |
<xsl:variable name="month" select="substring($dt, 6, 2)" /> | |
<xsl:variable name="day" select="substring($dt, 9, 2)" /> | |
<xsl:if test="number($year) and | |
substring($dt, 5, 1) = '-' and | |
$month <= 12 and | |
substring($dt, 8, 1) = '-' and | |
$day <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:variable name="month-days" select="sum(document('')/*/date:month-lengths/date:month[position() < $month])" /> | |
<xsl:variable name="days"> | |
<xsl:choose> | |
<xsl:when test="$leap and $month > 2"> | |
<xsl:value-of select="$month-days + $day + 1" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$month-days + $day" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="y-1" select="$year - 1" /> | |
<xsl:value-of select="(($y-1 + floor($y-1 div 4) - | |
floor($y-1 div 100) + floor($y-1 div 400) + | |
$days) | |
mod 7) + 1" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<func:result select="string(document('')/*/date:days/date:day[number($day-of-week)]/@abbr)" /> | |
</func:function> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:day-abbreviation - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/day-abbreviation">day-abbreviation</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>2<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.day-abbreviation.xml">date.day-abbreviation.xml</a><br/><b>Function Package: </b><a href="date.day-abbreviation.zip">date.day-abbreviation.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:day-abbreviation</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:day-abbreviation</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:day-abbreviation</code> 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 <code>date:date-time</code> is used the default argument. | |
</p><p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li></ul><p> | |
If the date/time string is not in one of these formats, then the empty string (<code>''</code>) is returned. | |
</p><p> | |
The result is a three-letter English day abbreviation: one of <code>'Sun'</code>, <code>'Mon'</code>, <code>'Tue'</code>, <code>'Wed'</code>, <code>'Thu'</code> or <code>'Fri'</code>. | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:day-abbreviation</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a></td><td>6.4.2</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a></td><td>2.4.D1</td><td>2</td></tr><tr><td class="rowhead"><a href="http://4Suite.org">4XSLT, from 4Suite.</a></td><td>0.12.0a3</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>2</td></tr></table><p> | |
The following implementations of <code>date:day-abbreviation</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.day-abbreviation.function.xsl.html">EXSLT Function</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-11</td><td><a href="date.day-abbreviation.function.xsl">date.day-abbreviation.function.xsl</a></td></tr><tr><td class="rowhead"><a href="date.day-abbreviation.template.xsl.html">XSLT Template</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-11</td><td><a href="date.day-abbreviation.template.xsl">date.day-abbreviation.template.xsl</a></td></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Previous Version: </b><a href="date.day-abbreviation.1.html">date.day-abbreviation.1.html</a></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">2</td><td style="width: 5em;">2001-06-11</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Removed second (optional date format) argument.</li><li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.1</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.2</td><td style="width: 5em;">2001-07-20</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description></p></td></tr><tr><td class="rowhead">2.3</td><td style="width: 5em;">2002-02-04</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Corrected return value - empty string rather than NaN. | |
</dc:description></p></td></tr><tr><td class="rowhead">2.4</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description></p></td></tr><tr><td class="rowhead">2.5</td><td style="width: 5em;">2002-11-12</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Updated 4XSLT version to 0.12.0a3.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/day-abbreviation/date.day-abbreviation.html">http://www.exslt.org/date/functions/day-abbreviation/date.day-abbreviation.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0"?> | |
<?xml-stylesheet type="text/xsl" href=""?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<date:month-lengths> | |
<date:month>31</date:month> | |
<date:month>28</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
</date:month-lengths> | |
<date:days> | |
<date:day abbr="Sun">Sunday</date:day> | |
<date:day abbr="Mon">Monday</date:day> | |
<date:day abbr="Tue">Tuesday</date:day> | |
<date:day abbr="Wed">Wednesday</date:day> | |
<date:day abbr="Thu">Thursday</date:day> | |
<date:day abbr="Fri">Friday</date:day> | |
<date:day abbr="Sat">Saturday</date:day> | |
</date:days> | |
<xsl:template name="date:day-abbreviation"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-')" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="day-of-week"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:variable name="year" select="substring($dt, 1, 4)" /> | |
<xsl:variable name="leap" select="(not($year mod 4) and $year mod 100) or not($year mod 400)" /> | |
<xsl:variable name="month" select="substring($dt, 6, 2)" /> | |
<xsl:variable name="day" select="substring($dt, 9, 2)" /> | |
<xsl:if test="number($year) and | |
substring($dt, 5, 1) = '-' and | |
$month <= 12 and | |
substring($dt, 8, 1) = '-' and | |
$day <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:variable name="month-days" select="sum(document('')/*/date:month-lengths/date:month[position() < $month])" /> | |
<xsl:variable name="days" select="$month-days + $day + boolean($leap and $month > 2)" /> | |
<xsl:variable name="y-1" select="$year - 1" /> | |
<xsl:value-of select="(($y-1 + floor($y-1 div 4) - | |
floor($y-1 div 100) + floor($y-1 div 400) + | |
$days) | |
mod 7) + 1" /> | |
</xsl:if> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:value-of select="document('')/*/date:days/date:day[number($day-of-week)]/@abbr" /> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="2" module="date" status="implemented"> | |
<exslt:name>day-abbreviation</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-abbreviation</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Removed second (optional date format) argument.</li> | |
<li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2.1"> | |
<exslt:version>2.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2.2"> | |
<exslt:version>2.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-07-20</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2.3"> | |
<exslt:version>2.3</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2002-02-04</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Corrected return value - empty string rather than NaN. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2.4"> | |
<exslt:version>2.4</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.2.5"> | |
<exslt:version>2.5</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-11-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Updated 4XSLT version to 0.12.0a3.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:day-abbreviation</code> 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 <code>date:date-time</code> is used the default argument. | |
</p> | |
<p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p> | |
<ul> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li> | |
</ul> | |
<p> | |
If the date/time string is not in one of these formats, then the empty string (<code>''</code>) is returned. | |
</p> | |
<p> | |
The result is a three-letter English day abbreviation: one of <code>'Sun'</code>, <code>'Mon'</code>, <code>'Tue'</code>, <code>'Wed'</code>, <code>'Thu'</code> or <code>'Fri'</code>. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="string" /> | |
<exslt:arg name="date-time" type="string" | |
optional="yes" default="date:date-time()" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="SAXON from Michael Kay" | |
vendor-url="http://users.iclway.co.uk/mhkay/saxon/index.html" | |
vendor-version="6.4.2" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="Xalan-J from Apache" | |
vendor-url="http://xml.apache.org/xalan-j" | |
vendor-version="2.4.D1" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="4XSLT, from 4Suite." | |
vendor-url="http://4Suite.org" | |
vendor-version="0.12.0a3" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.day-abbreviation.function.xsl" language="exslt:exslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.day-abbreviation.template.xsl" language="exslt:xslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-abbreviation</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-abbreviation</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-abbreviation.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="date.day-abbreviation.function.xsl"/> | |
<import href="date.day-abbreviation.template.xsl"/> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<func:function name="date:day"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-') and | |
not(starts-with($date-time, '---'))" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="day"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:choose> | |
<xsl:when test="starts-with($dt, '---') and | |
$dt-length = 5 and | |
substring($dt, 4, 2) <= 31"> | |
<xsl:value-of select="substring($dt, 4, 2)" /> | |
</xsl:when> | |
<xsl:when test="number(substring($dt, 1, 4)) and | |
substring($dt, 5, 1) = '-' and | |
substring($dt, 6, 2) <= 12 and | |
substring($dt, 8, 1) = '-' and | |
substring($dt, 9, 2) <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:value-of select="substring($dt, 9, 2)" /> | |
</xsl:when> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:variable> | |
<func:result select="number($day)" /> | |
</func:function> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:day-in-month - Implementer Page</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/day-in-month">day-in-month</a> - Implementer Page</h1><table><tr><td id="menu"><p class="level1"><a href="index.html">User Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/date.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/date.add.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/date.add-duration.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/date.date.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/date.date-time.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/date.day-abbreviation.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/date.day-in-month.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/date.day-in-week.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/date.day-in-year.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/date.day-name.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/date.day-of-week-in-month.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/date.difference.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/date.duration.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/date.format-date.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/date.hour-in-day.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/date.leap-year.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/date.minute-in-hour.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/date.month-abbreviation.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/date.month-in-year.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/date.month-name.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/date.parse-date.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/date.second-in-minute.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/date.seconds.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/date.sum.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/date.time.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/date.week-in-month.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/date.week-in-year.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/date.year.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/date.date-format.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/dyn.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/exsl.html">Common</a></p><p class="level2"><a href="../../../func/func.html">Functions</a></p><p class="level2"><a href="../../../math/math.html">Math</a></p><p class="level2"><a href="../../../random/random.html">Random</a></p><p class="level2"><a href="../../../regexp/regexp.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/set.html">Sets</a></p><p class="level2"><a href="../../../str/str.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Version: </b>2<br/><b>Status: </b>implemented<br/><b>User Page: </b><a href="index.html">index.html</a><br/><b>XML Definition: </b><a href="date.day-in-month.xml">date.day-in-month.xml</a><br/><b>Function Package: </b><a href="date.day-in-month.zip">date.day-in-month.zip</a></p><h4>Function Syntax</h4><pre><var>number</var> <b>date:day-in-month</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:day-in-month</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:day-in-month</code> function returns the day of a date as a number. If no argument is given, then the current local date/time, as returned by <code>date:date-time</code> is used the default argument. | |
</p><p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gMonthDay" class="offsite"><code>xs:gMonthDay</code></a> (<code>--<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gDay" class="offsite"><code>xs:gDay</code></a> (<code>---<var>DD</var></code>) | |
</li></ul><p> | |
If the date/time string is not in one of these formats, then <code>NaN</code> is returned. | |
</p></div><p> | |
An implementation of this extension | |
function | |
in the EXSLT date namespace must conform to the behaviour described in this document. | |
</p><h2>Implementations</h2><p> | |
Built-in support for <code>date:day-in-month</code> is available in the following XSLT processors: | |
</p><table><tr><th class="rowhead">Processor</th><th>Processor Version</th><th>Implemented Version</th></tr><tr><td class="rowhead"><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a></td><td>6.4.2</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a></td><td>2.4.D1</td><td>2</td></tr><tr><td class="rowhead"><a href="http://4Suite.org">4XSLT, from 4Suite.</a></td><td>0.12.0a3</td><td>2</td></tr><tr><td class="rowhead"><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a></td><td>1.0.19</td><td>2</td></tr></table><p> | |
The following implementations of <code>date:day-in-month</code> are available: | |
</p><table><tr><th class="rowhead">Language</th><th>Implemented Version</th><th>Creator</th><th>Date</th><th>Download</th></tr><tr><td class="rowhead"><a href="date.day-in-month.function.xsl.html">EXSLT Function</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.day-in-month.function.xsl">date.day-in-month.function.xsl</a></td></tr><tr><td class="rowhead"><a href="date.day-in-month.template.xsl.html">XSLT Template</a></td><td>2</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td>2001-06-10</td><td><a href="date.day-in-month.template.xsl">date.day-in-month.template.xsl</a></td></tr><tr><td class="rowhead"><a href="date.js.html">Javascript</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-11</td><td><a href="date.js">date.js</a></td></tr><tr><td class="rowhead"><a href="date.msxsl.xsl.html">Msxsl</a></td><td>2</td><td><a href="mailto:[email protected]">Chris Bayes</a></td><td>2001-06-16</td><td><a href="date.msxsl.xsl">date.msxsl.xsl</a></td></tr></table><h2>Change History</h2><p><b>Previous Version: </b><a href="date.day-in-month.1.html">date.day-in-month.1.html</a></p><table><tr><th class="rowhead">Version</th><th>Modified</th><th>By</th><th>Details</th></tr><tr><td class="rowhead">2</td><td style="width: 5em;">2001-06-10</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Removed second (optional date format) argument.</li><li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.1</td><td style="width: 5em;">2001-06-16</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"><ul><li>Updated Javascript implementation.</li><li>Added Microsoft-specific stylesheet.</li></ul></dc:description></td></tr><tr><td class="rowhead">2.2</td><td style="width: 5em;">2001-07-20</td><td><a href="mailto:[email protected]">Jeni Tennison</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description></p></td></tr><tr><td class="rowhead">2.3</td><td style="width: 5em;">2002-08-21</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description></p></td></tr><tr><td class="rowhead">2.4</td><td style="width: 5em;">2002-11-12</td><td><a href="mailto:[email protected]">Craig Stewart</a></td><td style="text-align: left;"><p><dc:description xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:exslt="http://exslt.org/documentation">Updated 4XSLT version to 0.12.0a3.</dc:description></p></td></tr></table></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/day-in-month/date.day-in-month.html">http://www.exslt.org/date/functions/day-in-month/date.day-in-month.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<xsl:template name="date:day"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-') and | |
not(starts-with($date-time, '---'))" /> | |
<xsl:variable name="dt-no-neg"> | |
<xsl:choose> | |
<xsl:when test="$neg or starts-with($date-time, '+')"> | |
<xsl:value-of select="substring($date-time, 2)" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="dt-no-neg-length" select="string-length($dt-no-neg)" /> | |
<xsl:variable name="timezone"> | |
<xsl:choose> | |
<xsl:when test="substring($dt-no-neg, $dt-no-neg-length) = 'Z'">Z</xsl:when> | |
<xsl:otherwise> | |
<xsl:variable name="tz" select="substring($dt-no-neg, $dt-no-neg-length - 5)" /> | |
<xsl:if test="(substring($tz, 1, 1) = '-' or | |
substring($tz, 1, 1) = '+') and | |
substring($tz, 4, 1) = ':'"> | |
<xsl:value-of select="$tz" /> | |
</xsl:if> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:variable name="day"> | |
<xsl:if test="not(string($timezone)) or | |
$timezone = 'Z' or | |
(substring($timezone, 2, 2) <= 23 and | |
substring($timezone, 5, 2) <= 59)"> | |
<xsl:variable name="dt" select="substring($dt-no-neg, 1, $dt-no-neg-length - string-length($timezone))" /> | |
<xsl:variable name="dt-length" select="string-length($dt)" /> | |
<xsl:choose> | |
<xsl:when test="starts-with($dt, '---') and | |
$dt-length = 5 and | |
substring($dt, 4, 2) <= 31"> | |
<xsl:value-of select="substring($dt, 4, 2)" /> | |
</xsl:when> | |
<xsl:when test="number(substring($dt, 1, 4)) and | |
substring($dt, 5, 1) = '-' and | |
substring($dt, 6, 2) <= 12 and | |
substring($dt, 8, 1) = '-' and | |
substring($dt, 9, 2) <= 31 and | |
($dt-length = 10 or | |
(substring($dt, 11, 1) = 'T' and | |
substring($dt, 12, 2) <= 23 and | |
substring($dt, 14, 1) = ':' and | |
substring($dt, 15, 2) <= 59 and | |
substring($dt, 17, 1) = ':' and | |
substring($dt, 18) <= 60))"> | |
<xsl:value-of select="substring($dt, 9, 2)" /> | |
</xsl:when> | |
</xsl:choose> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:value-of select="number($day)" /> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<exslt:function xmlns:exslt="http://exslt.org/documentation" | |
version="2" module="date" status="implemented"> | |
<exslt:name>day-in-month</exslt:name> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-in-month</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-10</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Removed second (optional date format) argument.</li> | |
<li>Added implementations in Javascript, XSLT and EXSLT - Functions.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.2.1"> | |
<exslt:version>2.1</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
<ul> | |
<li>Updated Javascript implementation.</li> | |
<li>Added Microsoft-specific stylesheet.</li> | |
</ul> | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.2.2"> | |
<exslt:version>2.2</exslt:version> | |
<dc:creator email="[email protected]" | |
url="http://www.jenitennison.com/"> | |
Jeni Tennison | |
</dc:creator> | |
<dc:date>2001-07-20</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml"> | |
Added implementation in Saxon 6.4.2. | |
</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.2.3"> | |
<exslt:version>2.3</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-08-21</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Added Xalan-J, libxslt and 4XSLT implementation to the list.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.2.4"> | |
<exslt:version>2.4</exslt:version> | |
<dc:creator email="[email protected]" | |
url="">Craig Stewart</dc:creator> | |
<dc:date>2002-11-12</dc:date> | |
<dc:description xmlns="http://www.w3.org/1999/xhtml">Updated 4XSLT version to 0.12.0a3.</dc:description> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml" | |
xmlns=""> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
The <code>date:day-in-month</code> function returns the day of a date as a number. If no argument is given, then the current local date/time, as returned by <code>date:date-time</code> is used the default argument. | |
</p> | |
<p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p> | |
<ul> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#gMonthDay" class="offsite"><code>xs:gMonthDay</code></a> (<code>--<var>MM</var>-<var>DD</var></code>) | |
</li> | |
<li> | |
<a href="http://www.w3.org/TR/xmlschema-2/#gDay" class="offsite"><code>xs:gDay</code></a> (<code>---<var>DD</var></code>) | |
</li> | |
</ul> | |
<p> | |
If the date/time string is not in one of these formats, then <code>NaN</code> is returned. | |
</p> | |
</html:div> | |
</exslt:doc> | |
<exslt:definition xmlns:xs="http://www.w3.org/2001/XMLSchema"> | |
<exslt:return type="number" /> | |
<exslt:arg name="date-time" type="string" | |
optional="yes" default="date:date-time()" /> | |
</exslt:definition> | |
<exslt:implementations> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="SAXON from Michael Kay" | |
vendor-url="http://users.iclway.co.uk/mhkay/saxon/index.html" | |
vendor-version="6.4.2" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="Xalan-J from Apache" | |
vendor-url="http://xml.apache.org/xalan-j" | |
vendor-version="2.4.D1" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="4XSLT, from 4Suite." | |
vendor-url="http://4Suite.org" | |
vendor-version="0.12.0a3" /> | |
<exslt:vendor-implementation | |
version="2" | |
vendor="libxslt from Daniel Veillard et al." | |
vendor-url="http://xmlsoft.org/XSLT/" | |
vendor-version="1.0.19" /> | |
<exslt:implementation src="date.day-in-month.function.xsl" language="exslt:exslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.day-in-month.template.xsl" language="exslt:xslt" | |
version="2"> | |
<exslt:doc xmlns:html="http://www.w3.org/1999/xhtml"> | |
<html:div xmlns="http://www.w3.org/1999/xhtml"> | |
<p> | |
This implementation relies on <a href="../date-time/date.date-time.html"><code>date:date-time()</code></a> being available in order to get the current date/time. If it isn't, it uses the global parameter <code>$date:date-time</code> as the current date/time. | |
</p> | |
</html:div> | |
</exslt:doc> | |
</exslt:implementation> | |
<exslt:implementation src="date.js" language="exslt:javascript" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.js"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-in-month</dc:subject> | |
<dc:subject>Javascript</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.js.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-11</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.js.2"> | |
<exslt:version>2</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
<exslt:implementation src="date.msxsl.xsl" language="exslt:msxsl" | |
version="2"> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.msxsl"> | |
<dc:subject>EXSLT</dc:subject> | |
<dc:subject>date</dc:subject> | |
<dc:subject>day-in-month</dc:subject> | |
<dc:subject>MSXML</dc:subject> | |
<exslt:revision> | |
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
ID="date:day-in-month.msxsl.1"> | |
<exslt:version>1</exslt:version> | |
<dc:creator xmlns:vcf="http://www.ietf.org/internet-drafts/draft-dawson-vcard-xml-dtd-03.txt" rdf:parseType="Resource"> | |
<vcf:fn>Chris Bayes</vcf:fn> | |
<vcf:email>[email protected]</vcf:email> | |
<vcf:url>http://www.bayes.co.uk</vcf:url> | |
</dc:creator> | |
<dc:date>2001-06-16</dc:date> | |
</rdf:Description> | |
</exslt:revision> | |
</rdf:Description> | |
</exslt:implementation> | |
</exslt:implementations> | |
<exslt:use-cases /> | |
</exslt:function> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt.org/functions" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="date.day-in-month.function.xsl"/> | |
<import href="date.day-in-month.template.xsl"/> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:script language="exslt:msxsl" implements-prefix="date" src="date.msxsl.xsl"/> | |
</stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<func:script language="exslt:javascript" implements-prefix="date" src="date.js"/> | |
<func:function name="date:duration"> | |
<xsl:param name="seconds"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:seconds')"> | |
<xsl:value-of select="date:seconds()" /> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="duration"> | |
<xsl:variable name="day-s" select="60 * 60 * 24" /> | |
<xsl:variable name="hour-s" select="60 * 60" /> | |
<xsl:variable name="min-s" select="60" /> | |
<xsl:if test="$seconds < 0">-</xsl:if> | |
<xsl:text>P</xsl:text> | |
<xsl:variable name="s" select="$seconds * ((($seconds >= 0) * 2) - 1)" /> | |
<xsl:variable name="days" select="floor($s div $day-s)" /> | |
<xsl:variable name="hours" select="floor(($s - ($days * $day-s)) div $hour-s)" /> | |
<xsl:variable name="mins" select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)" /> | |
<xsl:variable name="secs" select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)" /> | |
<xsl:if test="$days"> | |
<xsl:value-of select="$days" /> | |
<xsl:text>D</xsl:text> | |
</xsl:if> | |
<xsl:if test="$hours or $mins or $secs">T</xsl:if> | |
<xsl:if test="$hours"> | |
<xsl:value-of select="$hours" /> | |
<xsl:text>H</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mins"> | |
<xsl:value-of select="$mins" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$secs"> | |
<xsl:value-of select="$secs" /> | |
<xsl:text>S</xsl:text> | |
</xsl:if> | |
</xsl:variable> | |
<func:result select="string($duration)" /> | |
</func:function> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<?xml-stylesheet type="text/xsl" href=""?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
extension-element-prefixes="date"> | |
<xsl:import href="functions/add/date.add.template.xsl" /> | |
<xsl:template match="/"> | |
<xsl:message terminate="yes"> | |
<xsl:call-template name="date:add"> | |
<xsl:with-param name="date-time" select="'1900-01-01'" /> | |
<xsl:with-param name="duration"> | |
<xsl:call-template name="date:duration"> | |
<xsl:with-param name="seconds" select="(37257.041667 - 2) * 60 * 60 * 24" /> | |
</xsl:call-template> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:message> | |
</xsl:template> | |
<xsl:template name="date:duration"> | |
<xsl:param name="seconds"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:seconds')"> | |
<xsl:value-of select="date:seconds()" /> | |
</xsl:when> | |
<xsl:otherwise>0</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="duration"> | |
<xsl:variable name="day-s" select="60 * 60 * 24" /> | |
<xsl:variable name="hour-s" select="60 * 60" /> | |
<xsl:variable name="min-s" select="60" /> | |
<xsl:if test="$seconds < 0">-</xsl:if> | |
<xsl:text>P</xsl:text> | |
<xsl:variable name="s" select="$seconds * ((($seconds >= 0) * 2) - 1)" /> | |
<xsl:variable name="days" select="floor($s div $day-s)" /> | |
<xsl:variable name="hours" select="floor(($s - ($days * $day-s)) div $hour-s)" /> | |
<xsl:variable name="mins" select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)" /> | |
<xsl:variable name="secs" select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)" /> | |
<xsl:if test="$days"> | |
<xsl:value-of select="$days" /> | |
<xsl:text>D</xsl:text> | |
</xsl:if> | |
<xsl:if test="$hours or $mins or $secs">T</xsl:if> | |
<xsl:if test="$hours"> | |
<xsl:value-of select="$hours" /> | |
<xsl:text>H</xsl:text> | |
</xsl:if> | |
<xsl:if test="$mins"> | |
<xsl:value-of select="$mins" /> | |
<xsl:text>M</xsl:text> | |
</xsl:if> | |
<xsl:if test="$secs"> | |
<xsl:value-of select="$secs" /> | |
<xsl:text>S</xsl:text> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:value-of select="$duration" /> | |
</xsl:template> | |
</xsl:stylesheet> |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" | |
extension-element-prefixes="date msxsl"> | |
<msxsl:script language="Javascript" implements-prefix="date"> | |
<![CDATA[ | |
/** | |
<doc:module date="2001-06-12"> | |
<doc:module>exslt:date-time</doc:module> | |
<doc:name>dates</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:language>exslt:javascript</doc:language> | |
<doc:meta> | |
<doc:author email="[email protected]" url="http://www.bayes.co.uk">Chris Bayes</doc:author> | |
<doc:summary>Implementation of EXSLT - Dates (http://www.exslt.org/date)</doc:summary> | |
<doc:todo>_validDuration is not 100%</doc:todo> | |
<doc:todo>All timezone code.</doc:todo> | |
</doc:meta> | |
</doc:module> | |
**/ | |
var gsSuppliedFormat = ""; | |
var gsLang = "en"; | |
var gaLang = new Array(); | |
// en | |
gaLang["en"] = new Array(); | |
gaLang["en"]["months"] = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); | |
gaLang["en"]["shortMonths"] = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); | |
gaLang["en"]["days"] = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); | |
gaLang["en"]["shortDays"] = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); | |
var gaDayNames = new Array(); | |
gaDayNames["sunday"] = 0;gaDayNames["monday"] = 1;gaDayNames["tuesday"] = 2;gaDayNames["wednesday"] = 3;gaDayNames["thursday"] = 4;gaDayNames["friday"] = 5;gaDayNames["saturday"] = 6; | |
var gaMonthCnt = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
var gaMonthCntL = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
function _isLeap(y){return ( ((y%4==0)&(y%100!=0))|(y%400==0) );} | |
function _dayOfWeek(y,d){return ( ((y-1)+Math.floor((y-1)/4)-Math.floor((y-1)/100)+Math.floor((y-1)/400)+d)%7);} | |
function _dayInYear(y,m,d){return (m==0?d:eval( (_isLeap(y)?gaMonthCntL.slice(0,m).join("+"):gaMonthCnt.slice(0,m).join("+")) )+(d*1) );} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>add</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function add(){// | |
var d1,d2; | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
(d2 = _validDuration(arguments[1]))) | |
return _formatDate(d2.addDate(d1), gsSuppliedFormat); | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>addDuration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="duration" type="string" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function addDuration(duration1, duration2){ | |
if ((d1 = _validDuration(duration1)) && (d2 = _validDuration(duration2))){ | |
var d1mnth = d1.years *12 + d1.months; | |
var d1secs = d1.days*86400 + d1.hours*3600 + d1.minutes*60 + (d1.seconds+'.'+d1.fraction)*1; | |
var d2mnth = d2.years *12 + d2.months; | |
var d2secs = d2.days*86400 + d2.hours*3600 + d2.minutes*60 + (d2.seconds+'.'+d2.fraction)*1; | |
var mnthdiff = (d1.pm+d1mnth)*1 + (d2.pm+d2mnth)*1; | |
var secsdiff = (d1.pm+d1secs)*1 + (d2.pm+d2secs)*1; | |
if ((mnthdiff < 0 && secsdiff > 0) || (mnthdiff > 0 && secsdiff < 0)) | |
return ''; | |
var secs = secsdiff % 60; | |
var pm = (mnthdiff<0||secsdiff<0?'-':''); | |
mnthdiff = Math.abs(mnthdiff); | |
secsdiff = Math.abs(secsdiff); | |
return _formatDuration(new Duration(pm, 0, mnthdiff, Math.floor(secsdiff/86400), Math.floor((secsdiff%86400)/3600), Math.floor((secsdiff%3600)/60), Math.floor(secs), Math.floor(secs%1))); | |
} | |
return ''; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>date</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function date(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _formatDate(oDate, "xs:date"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:date"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dateTime</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args /> | |
</doc:function> | |
**/ | |
function dateTime(){//must be UTC/Z | |
if (arguments.length > 0) | |
dateTime_invalidArgument.error; | |
var oDate = new Date(); | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayAbbreviation(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayAbbreviation(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayAbbreviation(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayAbbreviation(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortDays"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInMonth(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gDay")) | |
) | |
return oDate.getDate(); | |
else | |
return Number.NaN | |
}else | |
return new Date().getDate(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInWeek</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInWeek(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInWeek(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayInWeek(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayInWeek(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
return (oDate.getDay()-fdow<0?oDate.getDay()-fdow+7:oDate.getDay()-fdow)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
else | |
return Number.NaN; | |
}else{ | |
var oDate = new Date() | |
return _dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()); | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayName(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayName(oDate.getDay(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _dayName(new Date().getDay(), arguments[1], arguments[2]); | |
} | |
function _dayName(num, dfName, ctx){ | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='days' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='day' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["days"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>dayOfWeekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function dayOfWeekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _dayOfWeekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _dayOfWeekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _dayOfWeekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
if (fdow > (oDate.getDay()-1)) | |
return Math.floor((oDate.getDate())/7)+1; | |
else | |
return Math.floor((oDate.getDate())/7) + 1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>difference</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function difference(){ | |
if (((d1 = _validDate(arguments[0], "xs:dateTime")) || | |
(d1 = _validDate(arguments[0], "xs:date")) || | |
(d1 = _validDate(arguments[0], "xs:gYearMonth")) || | |
(d1 = _validDate(arguments[0], "xs:gYear")) | |
) && | |
((d2 = _validDate(arguments[1], "xs:dateTime")) || | |
(d2 = _validDate(arguments[1], "xs:date")) || | |
(d2 = _validDate(arguments[1], "xs:gYearMonth")) || | |
(d2 = _validDate(arguments[1], "xs:gYear")) | |
) | |
){// truncation | |
var diffMil = d2.valueOf() - d1.valueOf(); | |
return _formatDuration(diffMil); | |
} | |
return Number.NaN; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>duration</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="seconds" type="number" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function duration(){ | |
var oDate; | |
if (arguments.length > 0){ | |
var nN = new Number(arguments[0]); | |
if (isNaN(nN)) | |
return ''; | |
else | |
return _formatDuration(arguments[0] * 1000); | |
}else | |
return _formatDuration(seconds() * 1000); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>formatDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function formatDate(date, format, dateF, ctx){ | |
var oDate; | |
var re; | |
var retString = ""; | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
for (var i=0; i < format.length;){ | |
var s = i; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;} | |
if (oDate.getFullYear() < 0){ | |
retString += "BC"; | |
}else{ | |
retString += "AD"; | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;} | |
if (i-s > 2){ | |
retString += oDate.getFullYear(); | |
}else{ | |
retString += oDate.getFullYear().toString().substring(4-(i-s)); | |
} | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;} | |
if (i-s <= 2){ | |
retString += pad(oDate.getMonth()+1); | |
}else{ | |
retString += _monthName(oDate.getMonth(), dateF, ctx); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;} | |
retString += pad(oDate.getDate()); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += pad(oDate.getHours()-12); | |
}else{ | |
retString += pad(oDate.getHours()); | |
} | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;} | |
retString += pad(oDate.getMinutes()); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;} | |
retString += pad(oDate.getSeconds()); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;} | |
retString += oDate.getMilliseconds(); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;} | |
retString += dayInWeek(oDate, dateF, ctx); | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;} | |
retString += _dayInYear(oDate.getFullYear(), oDate.getMonths(), oDate.getDate()); | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;} | |
retString += dayOfWeekInMonth(oDate, dateF, ctx); | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;} | |
retString += weekInYear(oDate, dateF, ctx); | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;} | |
retString += weekInMonth(oDate, dateF, ctx); | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;} | |
if (oDate.getHours() > 12 ){ | |
retString += "PM" | |
}else{ | |
retString += "AM" | |
} | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;} | |
retString += oDate.getHours(); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;} | |
if (oDate.getHours() > 12){ | |
retString += oDate.getHours()-12; | |
}else{ | |
retString += oDate.getHours(); | |
} | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;} | |
var tzo = oDate.getTimezoneOffset(); | |
retString += (tzo < 0?"-":"+") + pad(Math.abs(tzo / 60)) + ":" + pad(tzo % 60); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i++; | |
while (format.substr(i, 1)=="'"){i++;} | |
retString += "'"; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'" && i <= format.length){retString += format.substr(i++, 1);} | |
if (i >= format.length)return ''; | |
i++; | |
} | |
break; | |
default: | |
retString += format.substr(i, 1); | |
i++; | |
break; | |
} | |
} | |
} | |
return retString; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>hourInDay</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function hourInDay(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getHours(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getHours(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>leapYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="boolean" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function leapYear(){ | |
if (arguments.length > 0 && arguments[0] != ''){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return (_isLeap(oDate.getFullYear())?true:false); | |
else | |
return Number.NaN; | |
}else | |
return (_isLeap(new Date().getFullYear())?true:false); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>minuteInHour</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function minuteInHour(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getMinutes(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMinutes(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthAbbreviation</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthAbbreviation(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthAbbreviation(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthAbbreviation(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthAbbreviation(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/@abbr"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else{ //we could try local | |
return gaLang[gsLang]["shortMonths"][num*1]; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthInYear(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getMonth()+1; | |
else | |
return Number.NaN; | |
}else | |
return new Date().getMonth()+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>monthName</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function monthName(){// | |
if (arguments.length > 0){// && arguments[0] != '' | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gMonthDay")) | |
) | |
return _monthName(oDate.getMonth(), arguments[1], arguments[2]); | |
else | |
return ''; | |
}else | |
return _monthName(new Date().getMonth(), arguments[1], arguments[2]); | |
} | |
function _monthName(num, dfName, ctx){// | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectNodes( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/*[local-name()='months' and namespace-uri()='http://exslt.org/dates-and-times']" + | |
"/*[local-name()='month' and namespace-uri()='http://exslt.org/dates-and-times']/text()"); | |
if (nodes != null) | |
return nodes[num].nodeValue; | |
else | |
return ''; | |
}else | |
return gaLang[gsLang]["months"][num*1]; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>parseDate</doc:name> | |
<doc:version>1.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="input-format" type="string" default="''" optional="no"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="document" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function parseDate(date, inFormat, dfName, ctx){//0001 | |
var oDate; | |
if (inFormat == ""){ | |
if ((oDate = _validDate(date, "xs:dateTime")) || | |
(oDate = _validDate(date, "xs:date")) || | |
(oDate = _validDate(date, "xs:time")) || | |
(oDate = _validDate(date, "xs:gYearMonth")) || | |
(oDate = _validDate(date, "xs:gYear")) || | |
(oDate = _validDate(date, "xs:gMonthDay")) || | |
(oDate = _validDate(date, "xs:gMonth")) || | |
(oDate = _validDate(date, "xs:gDay")) | |
){ | |
return _formatDate(oDate, "xs:dateTime"); | |
} | |
}else{ | |
if (oDate = _validDate(date, inFormat)) | |
return _formatDate(oDate, dfName); | |
else | |
return ''; | |
} | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>secondInMinute</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function secondInMinute(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return oDate.getSeconds(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getSeconds(); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>seconds</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function seconds(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.valueOf()/1000; | |
else | |
if (oDate = _validDuration(arguments[0])) | |
return oDate.Seconds(); | |
else | |
return Number.NaN; | |
}else | |
return Math.floor(new Date().valueOf()/1000);//current local date/time | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>sum</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="durations" type="node-set" default="''" optional="no"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function sum(ctx){ | |
var sDate = "P0S"; | |
if (typeof(ctx) == "object"){ | |
if (ctx.length){ | |
for (var i=0; i < ctx.length; i++){ | |
ctxN = ctx.item(i); | |
if (ctxN.nodeType == 1){ | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
} | |
if (ctxN.nodeType == 2){ | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
} | |
} | |
}else{ | |
if (!(sDate = addDuration(sDate, ctx.nodeValue))) | |
return ''; | |
} | |
}else{ | |
return ''; | |
} | |
return sDate; | |
} | |
function _wander(ctx){ | |
var sDate = "P0S"; | |
for (var i=0; i < ctx.childNodes.length; i++){ | |
ctxN = ctx.childNodes[i]; | |
switch(ctxN.nodeType){ | |
case 1: | |
if (!(sDate = addDuration(sDate, _wander(ctxN)))) | |
return ''; | |
break; | |
case 3: | |
if (!(sDate = addDuration(sDate, ctxN.nodeValue))) | |
return ''; | |
break; | |
default: | |
break; | |
} | |
} | |
return sDate; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>time</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="string" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function time(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime"))|| | |
(oDate = _validDate(arguments[0], "xs:time")) | |
) | |
return _formatDate(oDate, "xs:time"); | |
else | |
return ''; | |
}else | |
return _formatDate(new Date(), "xs:time"); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInMonth</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInMonth(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInMonth(oDate, arguments[1], arguments[2]); | |
else | |
return Number.NaN; | |
}else | |
return _weekInMonth(new Date(), arguments[1], arguments[2]); | |
} | |
function _weekInMonth(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
} | |
var f = new Date(oDate); | |
f.setDate(1) | |
var fd = f.getDay()-1; | |
var dt = oDate.getDate() + fd - fdow; | |
return Math.floor((dt)/7)+1; | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>weekInYear</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="date-format" type="string" default="''" optional="yes"></doc:arg> | |
<doc:arg name="context" type="context" default="null" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function weekInYear(){ | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) | |
) | |
return _weekInYear(oDate, arguments[1], arguments[2]); | |
}else | |
return _weekInYear(new Date()); | |
return ''; | |
} | |
function _weekInYear(oDate, dfName, ctx){ | |
var fdow = 0; | |
if (ctx != null){ | |
var nodes = ctx.nextNode.selectSingleNode( | |
"//*[local-name()='date-format' and namespace-uri()='http://exslt.org/dates-and-times' and @name='" + dfName +"' ]" + | |
"/@first-day-of-week"); | |
if (nodes != null) | |
fdow = gaDayNames[nodes.nodeValue]; | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()+(7-fdow)) / 7); | |
}else | |
return Math.ceil(_dayInYear(oDate.getFullYear(), oDate.getMonth(), oDate.getDate()) / 7); | |
} | |
/** | |
<doc:function date="2001-06-12"> | |
<doc:name>year</doc:name> | |
<doc:version>2.0</doc:version> | |
<doc:return type="number" /> | |
<doc:args> | |
<doc:arg name="date" type="string" default="''" optional="yes"></doc:arg> | |
</doc:args> | |
</doc:function> | |
**/ | |
function year(){// | |
if (arguments.length > 0){ | |
var oDate; | |
if ((oDate = _validDate(arguments[0], "xs:dateTime")) || | |
(oDate = _validDate(arguments[0], "xs:date")) || | |
(oDate = _validDate(arguments[0], "xs:gYearMonth")) || | |
(oDate = _validDate(arguments[0], "xs:gYear")) | |
) | |
return oDate.getFullYear(); | |
else | |
return Number.NaN; | |
}else | |
return new Date().getFullYear(); | |
} | |
/** | |
Private functions. | |
**/ | |
function _validDate(date, format){ | |
var parts; | |
var oDate = new Date(-62135596800000); // Mon Jan 1 00:00:00 UTC 1 | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?)?(Z)?([\+\-][0-9]{2}:[0-9]{2})?$"); | |
if (parts=re.exec(date)){ | |
if (parts[10] == "Z"){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
}else{ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
oDate.setHours(parts[5], parts[7], parts[9]); | |
gsSuppliedFormat = "xs:dateTime"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1, parts[3]); | |
gsSuppliedFormat = "xs:date"; | |
return oDate; | |
} | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var re = new RegExp("^([0-9]{2})(:([0-9]{2})(:([0-9]{2}))?)?(Z)?$"); | |
if (parts=re.exec(date)){ | |
if (parts[9] == "Z"){ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
oDate.setMinutes(oDate.getMinutes()-oDate.getTimezoneOffset()); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
}else{ | |
oDate.setHours(parts[1], parts[3], parts[5]); | |
gsSuppliedFormat = "xs:time"; | |
return oDate; | |
} | |
} | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
var re = new RegExp("^([0-9]{4})-([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1], parts[2]-1); | |
gsSuppliedFormat = "xs:gYearMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gYear": //(CCYY) | |
var re = new RegExp("^([0-9]{4})$"); | |
if (parts=re.exec(date)){ | |
oDate.setFullYear(parts[1]); | |
gsSuppliedFormat = "xs:gYear"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonthDay": //(^--MM-DD) | |
var re = new RegExp("--([0-9]{2})-([0-9]{2})"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1, parts[2]); | |
gsSuppliedFormat = "xs:gMonthDay"; | |
return oDate; | |
} | |
break; | |
case "xs:gMonth": //(--MM--) | |
var re = new RegExp("^--([0-9]{2})--$"); | |
if (parts=re.exec(date)){ | |
oDate.setMonth(parts[1]-1); | |
gsSuppliedFormat = "xs:gMonth"; | |
return oDate; | |
} | |
break; | |
case "xs:gDay": //(---DD) | |
var re = new RegExp("^---([0-9]{2})$"); | |
if (parts=re.exec(date)){ | |
oDate.setDate(parts[1]); | |
gsSuppliedFormat = "xs:gDay"; | |
return oDate; | |
} | |
break; | |
default: | |
// format string | |
var Z = ""; | |
for (var i=0,j=0; i < format.length & oDate.toString() != "NaN";){ | |
var s = j; | |
switch(format.substr(i, 1)){ | |
case "G":// era designator (Text) AD | |
while (format.substr(i, 1)=="G"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "BC" || date.substr(s,j-s) == "bc"){ | |
oDate.setFullYear(-oDate.getFullYear); | |
} | |
break; | |
case "y":// year (Number) 1996 | |
while (format.substr(i, 1)=="y"){i++;j++;} | |
oDate.setYear(date.substr(s,j-s)); | |
break; | |
case "M":// month in year (Text & Number) July & 07 | |
while (format.substr(i, 1)=="M"){i++;j++;} | |
if (i-s <= 2){ | |
oDate.setMonth(date.substr(s,j-s)-1); | |
}else{ | |
oDate.setMonth(_monthNumber(date.substr(s,j-s))); | |
} | |
break; | |
case "d":// day in month (Number) 10 | |
while (format.substr(i, 1)=="d"){i++;j++;} | |
oDate.setDate(date.substr(s,j-s)); | |
break; | |
case "h":// hour in am/pm (1~12) (Number) 12 | |
while (format.substr(i, 1)=="h"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "H":// hour in day (0~23) (Number) 0 | |
while (format.substr(i, 1)=="H"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "m":// minute in hour (Number) 30 | |
while (format.substr(i, 1)=="m"){i++;j++;} | |
oDate.setMinutes(date.substr(s,j-s)); | |
break; | |
case "s":// second in minute (Number) 55 | |
while (format.substr(i, 1)=="s"){i++;j++;} | |
oDate.setSeconds(date.substr(s,j-s)); | |
break; | |
case "S":// millisecond (Number) 978 | |
while (format.substr(i, 1)=="S"){i++;j++;} | |
oDate.setMilliseconds(date.substr(s,j-s)); | |
break; | |
case "E":// day in week (Text) Tuesday | |
while (format.substr(i, 1)=="E"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "D":// day in year (Number) 189 | |
while (format.substr(i, 1)=="D"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "F":// day of week in month (Number) 2 (2nd Wed in July) | |
while (format.substr(i, 1)=="F"){i++;j++;} | |
break; | |
case "w":// week in year (Number) 27 | |
while (format.substr(i, 1)=="w"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "W":// week in month (Number) 2 | |
while (format.substr(i, 1)=="W"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
break; | |
case "a":// am/pm marker (Text) PM | |
while (format.substr(i, 1)=="a"){i++;j++;} | |
j++; | |
if (date.substr(s,j-s) == "PM" || date.substr(s,j-s) == "pm") | |
oDate.setHours(oDate.getHours()+12); | |
break; | |
case "k":// hour in day (1~24) (Number) 24 | |
while (format.substr(i, 1)=="k"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "K":// hour in am/pm (0~11) (Number) 0 | |
while (format.substr(i, 1)=="K"){i++;j++;} | |
oDate.setHours(date.substr(s,j-s)); | |
break; | |
case "z":// time zone (Text) Pacific Standard Time | |
while (format.substr(i, 1)=="z"){i++;j++;} | |
while (format.substr(i+1, 1)!=date.substr(j, 1)){j++;} | |
//oDate.setMinutes(oDate.getMinutes() - oDate.getTimezoneOffset()); | |
Z = date.substr(s,j-s); | |
break; | |
case "'":// escape for text (Delimiter) | |
if (format.substr(i+1, 1) == "'"){ | |
i+=2; | |
}else{ | |
i++; | |
while (format.substr(i, 1)!="'"){i++;j++;} | |
i++; | |
} | |
break; | |
default: | |
if (format.substr(i, 1) != date.substr(j, 1)){ | |
return false; | |
} | |
i++;j++; | |
break; | |
} | |
} | |
if (j < date.length) | |
return false; | |
if (oDate.toString() != "NaN"){ | |
if (Z != ""){ | |
var re = new RegExp("([\+\-][0-9]{2})?:([0-9]{2})?"); | |
if (parts=re.exec(Z)){ | |
// check GMT/BST | |
var tzo = parts[1]*60 + parts[2]; | |
//if (tzo != new Date().getTimezoneOffset()){ | |
// oDate.setMinutes(oDate.getMinutes() - (oDate.getTimezoneOffset() - tzo)) | |
//} | |
} | |
} | |
gsSuppliedFormat = "custom"; | |
return oDate; | |
} | |
break; | |
} | |
return false; | |
} | |
function _formatDate(oDate, format){ | |
if (oDate == Number.NaN)return Number.NaN; | |
switch(format){ | |
case "xs:dateTime": //(CCYY-MM-DDThh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()) + "T" + | |
pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:date": //(CCYY-MM-DD) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:time": //(hh:mm:ss) | |
var tzo = oDate.getTimezoneOffset(); | |
return pad(oDate.getHours()) + ":" + pad(oDate.getMinutes()) + ":" + pad(oDate.getSeconds()) + (tzo < 0?"-":"+") + pad(Math.abs(tzo/60)) + ":" + pad(tzo % 60); | |
break; | |
case "xs:gYearMonth": //(CCYY-MM) | |
return oDate.getFullYear() + "-" + pad(oDate.getMonth()+1); | |
break; | |
case "xs:gYear": //(CCYY) | |
return oDate.getFullYear(); | |
break; | |
case "xs:gMonthDay": //(--MM-DD) | |
return pad(oDate.getMonth() + 1) + "-" + pad(oDate.getDate()); | |
break; | |
case "xs:gMonth": //(--MM--) | |
return pad(oDate.getMonth()+1); | |
break; | |
case "xs:gDay": //(---DD) | |
return pad(oDate.getDate()); | |
break; | |
} | |
return false; | |
} | |
function pad(v){ | |
return (v<10?"0"+v:v); | |
} | |
function _validDuration(d){ | |
var parts; | |
var re = new RegExp("^([\-])?P(([0-9]+)Y)?(([0-9]+)M)?(([0-9]+)D)?((T)?(([0-9]+)H)?(([0-9]+)M)?((([0-9]+)(\.([0-9]+))?)S)?)?$"); | |
if (parts = re.exec(d)){ | |
if ((/T$/.exec(d)) || (parts[9] == "T" && parts[11]+parts[13]+parts[16]+parts[18]== ""))// ~(:+(|) duh!!! | |
return Number.NaN; | |
return new Duration(parts[1], parts[3], parts[5], parts[7], parts[11], parts[13], parts[16], parts[18]); | |
} | |
return Number.NaN; | |
} | |
function Duration(pm, years, months, days, hours, minutes, seconds, fraction){ | |
this.pm = pm; | |
this.years = years*1; | |
this.months = months*1; | |
this.days = days*1; | |
this.hours = hours*1; | |
this.minutes = minutes*1; | |
this.seconds = seconds*1; | |
this.fraction = fraction*1; | |
this.milliseconds = eval('0.'+fraction) * 100; | |
this.mask = ((this.years?1:0)<<6) + ((this.months?1:0)<<5) + ((this.days?1:0)<<4) + ((this.hours?1:0)<<3) + ((this.minutes?1:0)<<2) + ((this.seconds?1:0)<<1) + (this.milliseconds?1:0); | |
this.addDate = function(d){d.setFullYear(eval(this.pm+this.years)+d.getFullYear(),eval(this.pm+this.months)+d.getMonth(),eval(this.pm+this.days)+d.getDate());d.setHours(eval(this.pm+this.hours)+d.getHours(),eval(this.pm+this.minutes)+d.getMinutes(),eval(this.pm+this.seconds)+d.getSeconds());d.setMilliseconds(eval(this.pm+this.milliseconds));return d;} | |
this.Seconds = function(){if (this.years || this.months)return Number.NaN;return this.days*giDayMill + this.hours*giHourMill + this.minutes*giMinMill + this.seconds*giSecMill;} | |
} | |
var giYearMill = 31536000000; | |
var giMonthMill = 2592000000; | |
var giDayMill = 86400000; | |
var giHourMill = 3600000; | |
var giMinMill = 60000; | |
var giSecMill = 1000; | |
function _formatDuration(du){ | |
if (typeof(du) == "object"){ | |
var pm = du.pm; | |
var y = du.years; | |
var m = du.months; | |
var d = du.days; | |
var h = du.hours; | |
var n = du.minutes; | |
var s = du.seconds + du.milliseconds/1000; | |
if (y+m+d+h+n+s == 0) | |
return 'P0S'; | |
return pm + "P" + | |
(y!=0?y + "Y":'') + | |
(m!=0?m + "M":'') + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
}else{ | |
var pm = (du<0?'-':''); | |
du = Math.abs(du); | |
var d = Math.floor((du) / giDayMill); | |
var h = Math.floor((du % giDayMill) / giHourMill); | |
var n = Math.floor((du % giHourMill) / giMinMill); | |
var s = Math.floor((du % giMinMill) / giSecMill) + (du % giSecMill)/1000; | |
return pm + "P" + | |
(d!=0?d + "D":'') + | |
(h+n+s!=0?"T":'') + | |
(h!=0?h + "H":'') + | |
(n!=0?n + "M":'') + | |
(s!=0?s + "S":''); | |
} | |
} | |
]]> | |
</msxsl:script> | |
</xsl:stylesheet> |
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://exslt.org/dates%20and%20times" version="1.0" extension-element-prefixes="date" date:doc="http://www.exslt.org/date"> | |
<import href="functions/date-time/date.date-time.xsl"/> | |
<import href="functions/date/date.date.xsl"/> | |
<import href="functions/time/date.time.xsl"/> | |
<import href="functions/year/date.year.xsl"/> | |
<import href="functions/leap-year/date.leap-year.xsl"/> | |
<import href="functions/month-in-year/date.month-in-year.xsl"/> | |
<import href="functions/month-name/date.month-name.xsl"/> | |
<import href="functions/month-abbreviation/date.month-abbreviation.xsl"/> | |
<import href="functions/week-in-year/date.week-in-year.xsl"/> | |
<import href="functions/day-in-year/date.day-in-year.xsl"/> | |
<import href="functions/day-in-month/date.day-in-month.xsl"/> | |
<import href="functions/day-of-week-in-month/date.day-of-week-in-month.xsl"/> | |
<import href="functions/day-in-week/date.day-in-week.xsl"/> | |
<import href="functions/day-name/date.day-name.xsl"/> | |
<import href="functions/day-abbreviation/date.day-abbreviation.xsl"/> | |
<import href="functions/hour-in-day/date.hour-in-day.xsl"/> | |
<import href="functions/minute-in-hour/date.minute-in-hour.xsl"/> | |
<import href="functions/second-in-minute/date.second-in-minute.xsl"/> | |
<import href="functions/parse-date/date.parse-date.xsl"/> | |
<import href="functions/week-in-month/date.week-in-month.xsl"/> | |
<import href="functions/difference/date.difference.xsl"/> | |
<import href="functions/add/date.add.xsl"/> | |
<import href="functions/add-duration/date.add-duration.xsl"/> | |
<import href="functions/sum/date.sum.xsl"/> | |
<import href="functions/seconds/date.seconds.xsl"/> | |
<import href="functions/duration/date.duration.xsl"/> | |
</stylesheet> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date-format</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/elements/date-format">date-format</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.date-format.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.date-format.html">date.date-format.html</a><br/><b>Element Package: </b><a href="date.date-format.zip">date.date-format.zip</a></p><h4>Element Syntax</h4><pre><date:date-format | |
name = <var>qname</var> | |
calendar = "gregorian" | <var>qname-but-not-ncname</var> | |
lang = <var>language</var> | |
first-day-of-week = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday" | <var>string</var> /></pre><div><p> | |
The <code>date:date-format</code> element declares a <code>date format</code>, which controls the interpretation of a format pattern used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions. | |
</p><p> | |
If there is a <code>name</code> attribute, then the element declares a named date format; otherwise, it declares the default date format. The value of the <code>name</code> attribute is a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>, which is expanded as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]. It is an error to declare either the default date format or a date format with a given name more than once (even with different import precedence), unless it is declared every time with the same value for all attributes (taking into account any default values). | |
</p><p> | |
The <code>calendar</code> attribute specifies the calendar used to interpret format strings using the date format. The value must be a <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> does not have a prefix, then it identifies calendar specified in this document and must be <code>gregorian</code>. If the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> has a prefix, then the <a href="http://www.w3.org/TR/REC-xml-names#NT-QName" class="offsite">QName</a> is expanded into an expanded-name as described in [<a href="http://www.w3.org/TR/xslt#qname" class="offsite">2.4 Qualified Names</a>] of [<a href="http://www.w3.org/TR/xslt" class="offsite">XSLT</a>]; the expanded-name identifies the calendar; the interpretation of the format pattern used in the <a href="/date/functions/format-date"><code>date:format-date</code></a> and <a href="/date/functions/parse-date"><code>date:parse-date</code></a> functions in this case is not specified by this document. If the processor does not support the calendar used by the date format used in these functions, the result of these functions is an empty string (<code>''</code>). | |
</p><p> | |
If there is no <code>calendar</code> attribute or it has the value <code>gregorian</code>, then the date/time being processed is interpreted as using the Gregorian calendar, with the same assumptions as made by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.util.GregorianCalendar.html" class="offsite">GregorianCalendar</a> class. If this date format is used by the <a href="/date/functions/format-date"><code>date:format-date</code></a> or <a href="/date/functions/parse-date"><code>date:parse-date</code></a> function, then the format pattern strings that they use must be in the syntax specified by the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. The format pattern string is interpreted as described for the JDK 1.1 <a href="http://java.sun.com/products/jdk/1.1/docs/api/java.text.SimpleDateFormat.html" class="offsite">SimpleDateFormat</a> class. | |
</p><p> | |
The <code>lang</code> attribute specifies the language of the strings used in formatting the date; it has the same range of values as xml:lang [<a href="http://www.w3.org/TR/1998/REC-xml-19980210" class="offsite">XML</a>]; if no <code>lang</code> value is specified or if the processor does not support the specified language, the language should be determined from the system environment. | |
</p><p> | |
The <code>first-day-in-week</code> attribute specifies the day that's used as the first day of the week for calculating numbers of the week in month, week in year and day in week. If the calendar is Gregorian, then it must be one of the strings <code>sunday</code>, <code>monday</code>, <code>tuesday</code>, <code>wednesday</code>, <code>thursday</code>, <code>friday</code> or <code>saturday</code>. Otherwise the values are restricted based on the calendar being used for the date format. | |
</p></div><h2>Implementations</h2><p>There are currently no XSLT processors that we know of that support <code>date:date-format</code> natively.</p><p>There are currently no third-party implementations of <code>date:date-format</code>.</p></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/elements/date-format/index.html">http://www.exslt.org/date/elements/date-format/index.html</a> last modified 2001-05-13</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:add-duration</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/add-duration">add-duration</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.add-duration.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.add-duration.html">date.add-duration.html</a><br/><b>Function Package: </b><a href="date.add-duration.zip">date.add-duration.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:add-duration</b>(<var>string</var>, <var>string</var>)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:add-duration</b>"> | |
<xsl:with-param name="duration1" select="<var>string</var>" /> | |
<xsl:with-param name="duration2" select="<var>string</var>" /> | |
</xsl:call-template></pre><div><p> | |
The <code>date:add-duration</code> function returns the duration resulting from adding two durations together. | |
</p><p> | |
Both arguments are strings in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If either argument is not in this format, the function returns an empty string (<code>''</code>). | |
</p><p> | |
The return value is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p> | |
The durations can usually be added by summing the numbers given for each of the components in the durations. However, if the durations are differently signed, then this sometimes results in durations that are impossible to express in this syntax (e.g. <code>'P1M'</code> + <code>'-P1D'</code>). In these cases, the function returns an empty string (<code>''</code>). | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:add-duration</code>: | |
</p><ul><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:add-duration</code> are available in the following languages: | |
</p><ul><li><a href="date.add-duration.function.xsl">EXSLT Function</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.add-duration.template.xsl">XSLT Template</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/add-duration/index.html">http://www.exslt.org/date/functions/add-duration/index.html</a> last modified 2002-08-21</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:add</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/add">add</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.add.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.add.html">date.add.html</a><br/><b>Function Package: </b><a href="date.add.zip">date.add.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:add</b>(<var>string</var>, <var>string</var>)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:add</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" /> | |
<xsl:with-param name="duration" select="<var>string</var>" /> | |
</xsl:call-template></pre><div><p> | |
The <code>date:add</code> function returns the date/time resulting from adding a duration to a date/time. | |
</p><p> | |
The first argument must be right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gYearMonth" class="offsite"><code>xs:gYearMonth</code></a> (<code><var>CCYY</var>-<var>MM</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gYear" class="offsite"><code>xs:gYear</code></a> (<code><var>CCYY</var></code>) | |
</li></ul><p> | |
The second argument is a string in the format defined for <code>xs:duration</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#duration" class="offsite">3.2.6 duration</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p> | |
The return value is a right-truncated date/time strings in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and listed above. This value is calculated using the algorithm described in [<a href="http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes" class="offsite">Appendix E Adding durations to dateTimes</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:add</code>: | |
</p><ul><li><a href="http://4Suite.org">4XSLT, from 4Suite.</a> (version 0.12.0a3)</li><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:add</code> are available in the following languages: | |
</p><ul><li><a href="date.add.function.xsl">EXSLT Function</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.add.template.xsl">XSLT Template</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/add/index.html">http://www.exslt.org/date/functions/add/index.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date-time</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/date-time">date-time</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.date-time.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.date-time.html">date.date-time.html</a><br/><b>Function Package: </b><a href="date.date-time.zip">date.date-time.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:date-time</b>()</pre><div><p> | |
The <code>date:date-time</code> 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 <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
The date/time string format must include a time zone, either a <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:date-time</code>: | |
</p><ul><li><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a> (version 6.4.2)</li><li><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a> (version 2.4.D1)</li><li><a href="http://4Suite.org">4XSLT, from 4Suite.</a> (version 0.12.0a3)</li><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:date-time</code> are available in the following languages: | |
</p><ul><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/date-time/index.html">http://www.exslt.org/date/functions/date-time/index.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:date</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/date">date</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.date.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.date.html">date.date.html</a><br/><b>Function Package: </b><a href="date.date.zip">date.date.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:date</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:date</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:date</code> 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 <code>date:date-time</code> is used as a default argument. | |
</p><p> | |
The date/time string specified as an argument must be a string in the format defined as the lexical representation of either <code>xs:dateTime</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite">3.2.7 dateTime</a>] or <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. If the argument is not in either of these formats, <code>date:date</code> returns an empty string (<code>''</code>). | |
</p><p class="note"> | |
The date/time format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
The date is returned as a string with a lexical representation as defined for <code>xs:date</code> in [<a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite">3.2.9 date</a>] of [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. | |
</p><p class="note"> | |
The date format is basically <code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>, although implementers should consult [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>] and [<a href="http://www.iso.ch/markete/8601.pdf" class="offsite">ISO 8601</a>] for details. | |
</p><p> | |
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 <code>Z</code> to indicate Coordinated Universal Time or a <code>+</code> or <code>-</code> followed by the difference between the difference from <acronym>UTC</acronym> represented as <code><var>hh</var>:<var>mm</var></code>. If an argument is specified and it does not specify a time zone, then the date string format must not include a time zone. | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:date</code>: | |
</p><ul><li><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a> (version 6.4.2)</li><li><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a> (version 2.4.D1)</li><li><a href="http://4Suite.org">4XSLT, from 4Suite.</a> (version 0.12.0a3)</li><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:date</code> are available in the following languages: | |
</p><ul><li><a href="date.date.function.xsl">EXSLT Function</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.date.template.xsl">XSLT Template</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/date/index.html">http://www.exslt.org/date/functions/date/index.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:day-abbreviation</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/day-abbreviation">day-abbreviation</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.day-abbreviation.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.day-abbreviation.html">date.day-abbreviation.html</a><br/><b>Function Package: </b><a href="date.day-abbreviation.zip">date.day-abbreviation.zip</a></p><h4>Function Syntax</h4><pre><var>string</var> <b>date:day-abbreviation</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:day-abbreviation</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:day-abbreviation</code> 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 <code>date:date-time</code> is used the default argument. | |
</p><p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li></ul><p> | |
If the date/time string is not in one of these formats, then the empty string (<code>''</code>) is returned. | |
</p><p> | |
The result is a three-letter English day abbreviation: one of <code>'Sun'</code>, <code>'Mon'</code>, <code>'Tue'</code>, <code>'Wed'</code>, <code>'Thu'</code> or <code>'Fri'</code>. | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:day-abbreviation</code>: | |
</p><ul><li><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a> (version 6.4.2)</li><li><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a> (version 2.4.D1)</li><li><a href="http://4Suite.org">4XSLT, from 4Suite.</a> (version 0.12.0a3)</li><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:day-abbreviation</code> are available in the following languages: | |
</p><ul><li><a href="date.day-abbreviation.function.xsl">EXSLT Function</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.day-abbreviation.template.xsl">XSLT Template</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/day-abbreviation/index.html">http://www.exslt.org/date/functions/day-abbreviation/index.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/schema/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"><head><title>EXSLT - date:day-in-month</title><link rel="stylesheet" href="base.css"/></head><body><h1 id="#title"><a href="http://www.exslt.org/">EXSLT</a> - <a href="http://www.exslt.org/date">date</a>:<a href="http://www.exslt.org/date/functions/day-in-month">day-in-month</a></h1><table><tr><td id="menu"><p class="level1"><a href="date.day-in-month.html">Implementer Page</a></p><p class="level1"><a href="../../../howto.html">How To</a></p><p class="level1"><a href="../../../download.html">Downloads</a></p><p class="level1">Modules</p><p class="level2"><a href="../../../date/index.html">Dates and Times</a></p><p class="level3"><a href="../../functions/add/index.html">date:add()</a></p><p class="level3"><a href="../../functions/add-duration/index.html">date:add-duration()</a></p><p class="level3"><a href="../../functions/date/index.html">date:date()</a></p><p class="level3"><a href="../../functions/date-time/index.html">date:date-time()</a></p><p class="level3"><a href="../../functions/day-abbreviation/index.html">date:day-abbreviation()</a></p><p class="level3"><a href="../../functions/day-in-month/index.html">date:day-in-month()</a></p><p class="level3"><a href="../../functions/day-in-week/index.html">date:day-in-week()</a></p><p class="level3"><a href="../../functions/day-in-year/index.html">date:day-in-year()</a></p><p class="level3"><a href="../../functions/day-name/index.html">date:day-name()</a></p><p class="level3"><a href="../../functions/day-of-week-in-month/index.html">date:day-of-week-in-month()</a></p><p class="level3"><a href="../../functions/difference/index.html">date:difference()</a></p><p class="level3"><a href="../../functions/duration/index.html">date:duration()</a></p><p class="level3"><a href="../../functions/format-date/index.html">date:format-date()</a></p><p class="level3"><a href="../../functions/hour-in-day/index.html">date:hour-in-day()</a></p><p class="level3"><a href="../../functions/leap-year/index.html">date:leap-year()</a></p><p class="level3"><a href="../../functions/minute-in-hour/index.html">date:minute-in-hour()</a></p><p class="level3"><a href="../../functions/month-abbreviation/index.html">date:month-abbreviation()</a></p><p class="level3"><a href="../../functions/month-in-year/index.html">date:month-in-year()</a></p><p class="level3"><a href="../../functions/month-name/index.html">date:month-name()</a></p><p class="level3"><a href="../../functions/parse-date/index.html">date:parse-date()</a></p><p class="level3"><a href="../../functions/second-in-minute/index.html">date:second-in-minute()</a></p><p class="level3"><a href="../../functions/seconds/index.html">date:seconds()</a></p><p class="level3"><a href="../../functions/sum/index.html">date:sum()</a></p><p class="level3"><a href="../../functions/time/index.html">date:time()</a></p><p class="level3"><a href="../../functions/week-in-month/index.html">date:week-in-month()</a></p><p class="level3"><a href="../../functions/week-in-year/index.html">date:week-in-year()</a></p><p class="level3"><a href="../../functions/year/index.html">date:year()</a></p><p class="level3"><a href="../../elements/date-format/index.html">date:date-format</a></p><p class="level2"><a href="../../../dyn/index.html">Dynamic</a></p><p class="level2"><a href="../../../exsl/index.html">Common</a></p><p class="level2"><a href="../../../func/index.html">Functions</a></p><p class="level2"><a href="../../../math/index.html">Math</a></p><p class="level2"><a href="../../../random/index.html">Random</a></p><p class="level2"><a href="../../../regexp/index.html">Regular Expressions</a></p><p class="level2"><a href="../../../set/index.html">Sets</a></p><p class="level2"><a href="../../../str/index.html">Strings</a></p><p class="level1"><a href="../../../submissions/">Submissions</a></p><p class="level1"><a href="../../../list">Mailing List</a></p><p class="level1"><a href="../../../contact.html">Contact</a></p></td><td id="content"><p><b>Implementer Page: </b><a href="date.day-in-month.html">date.day-in-month.html</a><br/><b>Function Package: </b><a href="date.day-in-month.zip">date.day-in-month.zip</a></p><h4>Function Syntax</h4><pre><var>number</var> <b>date:day-in-month</b>(<var>string</var>?)</pre><h4>Template Syntax</h4><pre><xsl:call-template name="<b>date:day-in-month</b>"> | |
<xsl:with-param name="date-time" select="<var>string</var>" />? | |
</xsl:call-template></pre><div><p> | |
The <code>date:day-in-month</code> function returns the day of a date as a number. If no argument is given, then the current local date/time, as returned by <code>date:date-time</code> is used the default argument. | |
</p><p> | |
The date/time string specified as the argument is a left or right-truncated string in the format defined as the lexical representation of <code>xs:dateTime</code> in one of the formats defined in [<a href="http://www.w3.org/TR/xmlschema-2/" class="offsite">XML Schema Part 2: Datatypes</a>]. The permitted formats are as follows: | |
</p><ul><li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" class="offsite"><code>xs:dateTime</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var>T<var>hh</var>:<var>mm</var>:<var>ss</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#date" class="offsite"><code>xs:date</code></a> (<code><var>CCYY</var>-<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gMonthDay" class="offsite"><code>xs:gMonthDay</code></a> (<code>--<var>MM</var>-<var>DD</var></code>) | |
</li><li><a href="http://www.w3.org/TR/xmlschema-2/#gDay" class="offsite"><code>xs:gDay</code></a> (<code>---<var>DD</var></code>) | |
</li></ul><p> | |
If the date/time string is not in one of these formats, then <code>NaN</code> is returned. | |
</p></div><h2>Implementations</h2><p> | |
The following XSLT processors support <code>date:day-in-month</code>: | |
</p><ul><li><a href="http://users.iclway.co.uk/mhkay/saxon/index.html">SAXON from Michael Kay</a> (version 6.4.2)</li><li><a href="http://xml.apache.org/xalan-j">Xalan-J from Apache</a> (version 2.4.D1)</li><li><a href="http://4Suite.org">4XSLT, from 4Suite.</a> (version 0.12.0a3)</li><li><a href="http://xmlsoft.org/XSLT/">libxslt from Daniel Veillard et al.</a> (version 1.0.19)</li></ul><p> | |
Implementations of <code>date:day-in-month</code> are available in the following languages: | |
</p><ul><li><a href="date.day-in-month.function.xsl">EXSLT Function</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.day-in-month.template.xsl">XSLT Template</a> (by <a href="mailto:[email protected]">Jeni Tennison</a>)</li><li><a href="date.js">Javascript</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li><li><a href="date.msxsl.xsl">Msxsl</a> (by <a href="mailto:[email protected]">Chris Bayes</a>)</li></ul></td></tr></table><div id="colophon"><p><a href="http://www.exslt.org/date/functions/day-in-month/index.html">http://www.exslt.org/date/functions/day-in-month/index.html</a> last modified 2002-11-12</p></div></body></html> |
<?xml version="1.0" encoding="UTF-8"?> | |
<feed xmlns:gd="http://schemas.google.com/g/2005" | |
xmlns:cd="http://schemas.comcast.net/2008/cimdata" | |
xmlns="http://www.w3.org/2005/Atom"> | |
<id>tag:comcast.net,2008:zips/19125:lineups</id> | |
<title type="text">Lineups for Postal Code 19125</title> | |
<updated>2008-07-31T05:33:04.77-04:00</updated> | |
<author> | |
<name>Comcast Interactive Media</name> | |
</author> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA37745Y</id> | |
<title type="text">Comcast Center City - Philadelphia</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745Y.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA37745Y"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745Y/stations.atom" | |
readOnly="true"/> | |
</entry> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA37745X</id> | |
<title type="text">Comcast Center City - Philadelphia (Digital)</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745X.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA37745X"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745X/stations.atom" | |
readOnly="true"/> | |
</entry> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA37745R</id> | |
<title type="text">Comcast Center City - Philadelphia (Cable Ready)</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745R.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA37745R"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA37745R/stations.atom" | |
readOnly="true"/> | |
</entry> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA54787Y</id> | |
<title type="text">Comcast Philadelphia NE & NW - Philadelphia</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787Y.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA54787Y"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787Y/stations.atom" | |
readOnly="true"/> | |
</entry> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA54787X</id> | |
<title type="text">Comcast Philadelphia NE & NW - Philadelphia (Digital)</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787X.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA54787X"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787X/stations.atom" | |
readOnly="true"/> | |
</entry> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" | |
term="http://schemas.comcast.net/2008/cimdata#lineup"/> | |
<id>tag:comcast.net,2008:lineups/PA54787R</id> | |
<title type="text">Comcast Philadelphia NE & NW - Philadelphia (Cable Ready)</title> | |
<updated>2008-07-31-04:00</updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787R.atom"/> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="PA54787R"/> | |
<cd:timezone value="EASTERN"/> | |
<cd:timeoffset value="-4"/> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" | |
href="http://www.comcast.net/tvplanner/api/v2/lineups/PA54787R/stations.atom" | |
readOnly="true"/> | |
</entry> | |
</feed> |
<?xml version="1.0" encoding="UTF-8" ?> | |
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output encoding="UTF-8" indent="yes" method="xml" /> | |
<xsl:template match="/"> | |
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:cd="http://schemas.comcast.net/2008/cimdata"> | |
<id>tag:comcast.net,2008:zips/19125:lineups</id> | |
<title type="text">Lineups for Postal Code 19125</title> | |
<updated><xsl:value-of select="current-dateTime()"/></updated> | |
<author> | |
<name>Comcast Interactive Media</name> | |
</author> | |
<xsl:for-each select="headends/headend"> | |
<entry> | |
<category scheme="http://schemas.comcast.net/2008/cimdata#kind" term="http://schemas.comcast.net/2008/cimdata#lineup" /> | |
<id>tag:comcast.net,2008:lineups/<xsl:value-of select="@id" /></id> | |
<title type="text"><xsl:value-of select="@title" /></title> | |
<updated><xsl:value-of select="current-date()"/></updated> | |
<link href="http://www.comcast.net/tvplanner/api/v2/lineups/{@id}.atom" /> | |
<content type="text/xml"> | |
<cd:data> | |
<cd:sourceId value="{@id}" /> | |
<cd:timezone value="{@tz}" /> | |
<cd:timeoffset value="{@timeoffset}" /> | |
</cd:data> | |
</content> | |
<gd:feedLink rel="http://schemas.comcast.net/2008/cimdata#station" href="http://www.comcast.net/tvplanner/api/v2/lineups/{@id}/stations.atom" readOnly="true" /> | |
</entry> | |
</xsl:for-each> | |
</feed> | |
</xsl:template> | |
</xsl:stylesheet> |
<?xml version="1.0"?> | |
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:func="http://exslt.org/functions" | |
extension-element-prefixes="date func"> | |
<xsl:param name="date:date-time" select="'2000-01-01T00:00:00Z'" /> | |
<date:month-lengths> | |
<date:month>31</date:month> | |
<date:month>28</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
<date:month>30</date:month> | |
<date:month>31</date:month> | |
</date:month-lengths> | |
<func:function name="date:day-in-week"> | |
<xsl:param name="date-time"> | |
<xsl:choose> | |
<xsl:when test="function-available('date:date-time')"> | |
<xsl:value-of select="date:date-time()" /> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$date:date-time" /> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:param> | |
<xsl:variable name="neg" select="starts-with($date-time, '-')" /> | |
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)