Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('accepts "-2000-12-12T20:10:10.2" as input', () => {
const dateTime = DateTime.fromString('2000-12-12T20:10:10.2');
chai.assert.deepEqual(dateTime, new DateTime(2000, 12, 12, 20, 10, 10, 0.2, null));
});
it('accepts "2000-12-12T20:10:10.2+10:00" as input', () => {
const dateTime = DateTime.fromString('2000-12-12T20:10:10.2+10:00');
chai.assert.deepEqual(
dateTime,
new DateTime(
2000,
12,
12,
20,
10,
10,
0.2,
DayTimeDuration.fromTimezoneString('+10:00')
)
);
});
});
it('from xs:date', () =>
chai.assert.deepEqual(
castToType(
createAtomicValue(DateTime.fromString('2000-10-10+10:30'), 'xs:date'),
'xs:dateTime'
),
createAtomicValue(DateTime.fromString('2000-10-10T00:00:00+10:30'), 'xs:dateTime')
));
it('from xs:gYearMonth (throws XPTY0004)', () =>
it('turns date into xs:gYearMonth', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:gYearMonth'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:gYearMonth', 'is a gYearMonth');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('2018-06Z'),
'is June 2018'
);
});
it('turns date into xs:gDay', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:gDay'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:gDay', 'is a gDay');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('---22Z'),
'is 22nd'
);
});
it('turns date into xs:gMonthDay', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:gMonthDay'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:gMonthDay', 'is a gMonthDay');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('-06-22Z'),
'is 22nd June'
);
});
it('accepts "2000-12-12T20:10:10.2+10:00" as input', () => {
const dateTime = DateTime.fromString('2000-12-12T20:10:10.2+10:00');
chai.assert.deepEqual(dateTime, new DateTime(2000, 12, 12, 20, 10, 10, .2, DayTimeDuration.fromTimezoneString('+10:00')));
});
});
it('from xs:date', () =>
chai.assert.deepEqual(
castToType(
createAtomicValue(DateTime.fromString('2000-10-10+10:30'), 'xs:date'),
'xs:gYearMonth'
),
createAtomicValue(DateTime.fromString('2000-10+10:30'), 'xs:gYearMonth')
));
it('from xs:gYearMonth', () =>
it('turns date into xs:time', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:time'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:time', 'is a time');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('09:10:20Z'),
'is 09:10:20'
);
});
() =>
castToType(
createAtomicValue(DateTime.fromString('2000+10:30'), 'xs:gYear'),
'xs:anyURI'
),
'XPTY0004'