Skip to content

Commit b908fc7

Browse files
committed
[feature] Fix file sync module test, add more tests for xs:dateTimeStamp.
1 parent 48b426b commit b908fc7

File tree

5 files changed

+83
-9
lines changed

5 files changed

+83
-9
lines changed

exist-core/src/main/java/org/exist/xquery/OpNumeric.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ public String toString() {
229229
new OpEntry(ArithmeticOperator.ADDITION, Type.YEAR_MONTH_DURATION, Type.DATE_TIME, Type.DATE_TIME),
230230
new OpEntry(ArithmeticOperator.ADDITION, Type.DATE_TIME, Type.DAY_TIME_DURATION, Type.DATE_TIME),
231231
new OpEntry(ArithmeticOperator.ADDITION, Type.DAY_TIME_DURATION, Type.DATE_TIME, Type.DATE_TIME),
232+
new OpEntry(ArithmeticOperator.ADDITION, Type.DATE_TIME_STAMP, Type.YEAR_MONTH_DURATION, Type.DATE_TIME_STAMP),
233+
new OpEntry(ArithmeticOperator.ADDITION, Type.YEAR_MONTH_DURATION, Type.DATE_TIME_STAMP, Type.DATE_TIME_STAMP),
234+
new OpEntry(ArithmeticOperator.ADDITION, Type.DATE_TIME_STAMP, Type.DAY_TIME_DURATION, Type.DATE_TIME_STAMP),
235+
new OpEntry(ArithmeticOperator.ADDITION, Type.DAY_TIME_DURATION, Type.DATE_TIME_STAMP, Type.DATE_TIME_STAMP),
232236
new OpEntry(ArithmeticOperator.ADDITION, Type.YEAR_MONTH_DURATION, Type.YEAR_MONTH_DURATION, Type.YEAR_MONTH_DURATION),
233237
new OpEntry(ArithmeticOperator.ADDITION, Type.DAY_TIME_DURATION, Type.DAY_TIME_DURATION, Type.DAY_TIME_DURATION),
234238
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.NUMBER, Type.NUMBER, Type.NUMBER),
@@ -240,6 +244,9 @@ public String toString() {
240244
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME, Type.DATE_TIME, Type.DAY_TIME_DURATION),
241245
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME, Type.YEAR_MONTH_DURATION, Type.DATE_TIME),
242246
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME, Type.DAY_TIME_DURATION, Type.DATE_TIME),
247+
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME_STAMP, Type.DATE_TIME_STAMP, Type.DAY_TIME_DURATION),
248+
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME_STAMP, Type.YEAR_MONTH_DURATION, Type.DATE_TIME_STAMP),
249+
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DATE_TIME_STAMP, Type.DAY_TIME_DURATION, Type.DATE_TIME_STAMP),
243250
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.YEAR_MONTH_DURATION, Type.YEAR_MONTH_DURATION, Type.YEAR_MONTH_DURATION),
244251
new OpEntry(ArithmeticOperator.SUBTRACTION, Type.DAY_TIME_DURATION, Type.DAY_TIME_DURATION, Type.DAY_TIME_DURATION),
245252
new OpEntry(ArithmeticOperator.MULTIPLICATION, Type.NUMBER, Type.NUMBER, Type.NUMBER),

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public class DateTimeStampValue extends DateTimeValue {
3434

3535
private static final QName XML_SCHEMA_TYPE = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "dateTimeStamp");
3636

37-
public DateTimeStampValue(XMLGregorianCalendar calendar) throws XPathException {
37+
public DateTimeStampValue(final XMLGregorianCalendar calendar) throws XPathException {
3838
super(calendar);
3939
checkValidTimezone();
4040
}
4141

42-
public DateTimeStampValue(String dateTime) throws XPathException {
42+
public DateTimeStampValue(final String dateTime) throws XPathException {
4343
super(dateTime);
4444
checkValidTimezone();
4545
}
@@ -51,7 +51,7 @@ private void checkValidTimezone() throws XPathException {
5151
}
5252

5353
@Override
54-
public AtomicValue convertTo(int requiredType) throws XPathException {
54+
public AtomicValue convertTo(final int requiredType) throws XPathException {
5555
switch (requiredType) {
5656
case Type.DATE_TIME_STAMP:
5757
return this;
@@ -62,6 +62,11 @@ public AtomicValue convertTo(int requiredType) throws XPathException {
6262
}
6363
}
6464

65+
@Override
66+
protected AbstractDateTimeValue createSameKind(final XMLGregorianCalendar cal) throws XPathException {
67+
return new DateTimeStampValue(cal);
68+
}
69+
6570
@Override
6671
public int getType() {
6772
return Type.DATE_TIME_STAMP;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public ComputableValue plus(ComputableValue other) throws XPathException {
153153
}
154154
case Type.TIME:
155155
case Type.DATE_TIME:
156+
case Type.DATE_TIME_STAMP:
156157
case Type.DATE:
157158
final AbstractDateTimeValue date = (AbstractDateTimeValue) other;
158159
final XMLGregorianCalendar gc = (XMLGregorianCalendar) date.calendar.clone();

exist-core/src/test/xquery/dates/convert-dates.xql renamed to exist-core/src/test/xquery/dates/convert-dates.xqm

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,52 @@ function fd:convert-date-time-stamp($date as xs:dateTimeStamp) {
4141
format-dateTime($date, "[h00]:[m00] [P] on [FNn], [MNn] [D1o], [Y]", "en", (), ())
4242
};
4343

44+
declare
45+
%test:args("2022-05-17T16:24:06.003+02:00", "PT2H")
46+
%test:assertEquals("2022-05-17T18:24:06.003+02:00")
47+
function fd:add-test($date as xs:dateTimeStamp, $duration as xs:dayTimeDuration) {
48+
$duration + $date
49+
};
50+
51+
4452
(: verify that fn:current-dateTime() return type is xs:dateTimeStamp :)
4553
declare
4654
%test:assertEquals("true")
4755
function fd:current-dateTime-type() {
4856
fn:current-dateTime() instance of xs:dateTimeStamp
57+
};
58+
59+
declare
60+
%test:args("2022-05-17T16:24:06.003+02:00", "PT2H")
61+
%test:assertEquals("true")
62+
function fd:return-type-test($date as xs:dateTimeStamp, $duration as xs:dayTimeDuration) {
63+
($duration + $date) instance of xs:dateTimeStamp
64+
};
65+
66+
declare
67+
%test:args("not-a-dateTimeStamp")
68+
%test:assertError
69+
function fd:not-a-dateTimeStamp($date as xs:dateTimeStamp) {
70+
$date instance of xs:dateTimeStamp
71+
};
72+
73+
declare
74+
%test:args("2022-05-17T17:16:00.000")
75+
%test:assertError
76+
function fd:not-a-dateTimeStamp2($date as xs:dateTimeStamp) {
77+
$date instance of xs:dateTimeStamp
78+
};
79+
80+
declare
81+
%test:args("2022-05-17T17:16:00.000Z")
82+
%test:assertEquals("true")
83+
function fd:create-dateTimeStamp($date as xs:dateTimeStamp) {
84+
$date instance of xs:dateTimeStamp
85+
};
86+
87+
declare
88+
%test:args("2022-05-17T17:16:00.000+01:00")
89+
%test:assertEquals("true")
90+
function fd:create-dateTimeStamp2($date as xs:dateTimeStamp) {
91+
$date instance of xs:dateTimeStamp
4992
};

extensions/modules/file/src/main/java/org/exist/xquery/modules/file/Sync.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ private Map<String, Sequence> getOptions(final Sequence parameter) throws XPathE
178178
}
179179
options.put(EXCLUDES_OPT, seq);
180180

181-
checkOption(optionsMap, PRUNE_OPT, Type.BOOLEAN, options);
182-
checkOption(optionsMap, AFTER_OPT, Type.DATE_TIME, options);
181+
checkOption(optionsMap, PRUNE_OPT, options, Type.BOOLEAN);
182+
checkOption(optionsMap, AFTER_OPT, options, Type.DATE_TIME, Type.DATE_TIME_STAMP);
183183
} else if (parameter.itemAt(0).getType() == Type.DATE_TIME) {
184184
options.put(AFTER_OPT, parameter);
185185
} else {
@@ -192,25 +192,43 @@ private Map<String, Sequence> getOptions(final Sequence parameter) throws XPathE
192192
private void checkOption(
193193
final AbstractMapType optionsMap,
194194
final String name,
195-
final int expectedType,
196-
final Map<String, Sequence> options
195+
final Map<String, Sequence> options,
196+
final int... expectedTypes
197197
) throws XPathException {
198198
final Sequence p = optionsMap.get(new StringValue(name));
199199

200200
if (p.isEmpty()) {
201201
return; // nothing to do, continue
202202
}
203203

204-
if (p.hasMany() || p.getItemType() != expectedType) {
204+
if (p.hasMany() || !isExpectedType(p.getItemType(), expectedTypes)) {
205205
throw new XPathException(this, ErrorCodes.XPTY0004,
206206
"Invalid value type for option \"" + name + "\", expected " +
207-
Type.getTypeName(expectedType) + " got " +
207+
formatTypes(expectedTypes) + " got " +
208208
Type.getTypeName(p.itemAt(0).getType()));
209209
}
210210

211211
options.put(name, p);
212212
}
213213

214+
private boolean isExpectedType(final int actualType, final int... expectedTypes) {
215+
for(int type : expectedTypes) {
216+
if(type == actualType) {
217+
return true;
218+
}
219+
}
220+
return false;
221+
}
222+
223+
private String formatTypes(final int... expectedTypes) {
224+
StringBuilder buff = new StringBuilder(Type.getTypeName(expectedTypes[0]));
225+
for(int i = 1; i < expectedTypes.length; i++) {
226+
buff.append(", ");
227+
buff.append(Type.getTypeName(expectedTypes[i]));
228+
}
229+
return buff.toString();
230+
}
231+
214232
private Sequence startSync(
215233
final String target,
216234
final String collectionPath,

0 commit comments

Comments
 (0)