Skip to content

Commit 48b426b

Browse files
committed
[feature] Add tests for xs:dateTimeStamp implementation.
1 parent 13081d4 commit 48b426b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

exist-core/src/main/java/org/exist/xquery/value/DateTimeStampValue.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
122
package org.exist.xquery.value;
223

324
import org.exist.xquery.ErrorCodes;

exist-core/src/main/java/org/exist/xquery/value/StringValue.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ public AtomicValue convertTo(int requiredType) throws XPathException {
494494
return new TimeValue(value);
495495
case Type.DATE:
496496
return new DateValue(value);
497+
case Type.DATE_TIME_STAMP:
498+
return new DateTimeStampValue(value);
497499
case Type.DURATION:
498500
return new DurationValue(value);
499501
case Type.YEAR_MONTH_DURATION:
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
(:
2+
: eXist-db Open Source Native XML Database
3+
: Copyright (C) 2001 The eXist-db Authors
4+
:
5+
6+
: http://www.exist-db.org
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; either
11+
: version 2.1 of the License, or (at your option) any later version.
12+
:
13+
: This library is distributed in the hope that it will be useful,
14+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
: Lesser General Public License for more details.
17+
:
18+
: You should have received a copy of the GNU Lesser General Public
19+
: License along with this library; if not, write to the Free Software
20+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
:)
22+
xquery version "3.0";
23+
24+
module namespace fd="http://exist-db.org/xquery/test/convert-dates";
25+
26+
declare namespace test="http://exist-db.org/xquery/xqsuite";
27+
28+
(: verify that we can convert xs:string to :xs:dateTimeStamp :)
29+
declare
30+
%test:args("2012-06-26T23:14:22.566+02:00")
31+
%test:assertEquals("11:14 pm on Tuesday, June 26th, 2012")
32+
function fd:format-dateTimeStamp($date as xs:dateTimeStamp) {
33+
format-dateTime($date, "[h00]:[m00] [P] on [FNn], [MNn] [D1o], [Y]", "en", (), ())
34+
};
35+
36+
(: verify that we can't convert xs:string without timezone to :xs:dateTimeStamp :)
37+
declare
38+
%test:args("2012-06-26T23:14:22.566")
39+
%test:assertError
40+
function fd:convert-date-time-stamp($date as xs:dateTimeStamp) {
41+
format-dateTime($date, "[h00]:[m00] [P] on [FNn], [MNn] [D1o], [Y]", "en", (), ())
42+
};
43+
44+
(: verify that fn:current-dateTime() return type is xs:dateTimeStamp :)
45+
declare
46+
%test:assertEquals("true")
47+
function fd:current-dateTime-type() {
48+
fn:current-dateTime() instance of xs:dateTimeStamp
49+
};

0 commit comments

Comments
 (0)