openrosa-xpath-evaluator
Advanced tools
Comparing version 2.0.8 to 2.0.9
@@ -6,2 +6,7 @@ Change Log | ||
[2.0.9] - 2021-10-11 | ||
--------------------- | ||
##### Fixed | ||
- `decimal-date-time()` treated as local time when no offset specified | ||
[2.0.8] - 2021-09-10 | ||
@@ -8,0 +13,0 @@ --------------------- |
{ | ||
"name": "openrosa-xpath-evaluator", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "Wrapper for browsers' XPath evaluator with added support for OpenRosa extensions.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://enketo.org", |
@@ -23,3 +23,2 @@ const { getTimezoneOffsetAsTime } = require('./date-extensions'); | ||
TOO_FEW_ARGS = new Error('too few args'), | ||
MILLIS_PER_DAY = 1000 * 60 * 60 * 24, | ||
_round = function(num) { | ||
@@ -156,6 +155,8 @@ if(num < 0) { | ||
}, | ||
'decimal-date-time': function(date) { | ||
'decimal-date-time': function(r) { | ||
if(arguments.length > 1) throw TOO_MANY_ARGS; | ||
const res = Date.parse(asString(date)) / MILLIS_PER_DAY; | ||
return XPR.number(res); | ||
const days = dateStringToDays(asString(r)); | ||
return XPR.number(days); | ||
}, | ||
@@ -162,0 +163,0 @@ 'decimal-time': function(r) { |
@@ -1,2 +0,2 @@ | ||
const { assertThrow, assertNumberValue } = require('../helpers'); | ||
const { assertThrow, assertNumberValue, assertNumberRounded } = require('../helpers'); | ||
@@ -18,8 +18,9 @@ describe('#decimal-date-time()', () => { | ||
[ | ||
['decimal-date-time("1970-01-01")', 0], | ||
['decimal-date-time("1970-01-02")', 1], | ||
['decimal-date-time("1969-12-31")', -1] | ||
['decimal-date-time("1970-01-01")', 0.291667], | ||
['decimal-date-time("1970-01-02")', 1.291667], | ||
['decimal-date-time("1969-12-31")', -0.708333], | ||
['decimal-date-time("2021-10-06")', 18906.291667], | ||
].forEach( ([expr, expectedDaysSinceEpoch]) => { | ||
it('should convert ' + expr + ' into ' + expectedDaysSinceEpoch, () => { | ||
assertNumberValue(expr, expectedDaysSinceEpoch); | ||
assertNumberRounded(expr, expectedDaysSinceEpoch, 1000000); | ||
}); | ||
@@ -29,2 +30,15 @@ }); | ||
describe('with no offset specified', () => { | ||
[ | ||
['decimal-date-time("1970-01-01T00:00:00")', 0.291667], | ||
['decimal-date-time("1970-01-02T00:00:00.000")', 1.291667], | ||
['decimal-date-time("1969-12-31T00:00:00")', -0.708333], | ||
['decimal-date-time("2021-10-06T00:00:00.000")', 18906.291667], | ||
].forEach( ([expr, expectedDaysSinceEpoch]) => { | ||
it('should convert ' + expr + ' into ' + expectedDaysSinceEpoch, () => { | ||
assertNumberRounded(expr, expectedDaysSinceEpoch, 1000000); | ||
}); | ||
}); | ||
}); | ||
it('with invalid args, throws an error', () => { | ||
@@ -31,0 +45,0 @@ assertThrow('decimal-date-time("1970-01-01T00:00:00.000Z", 2)'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
380479
9182
0