Parse 'fortnight' as a duration of two weeks
This commit is contained in:
1 parent
2815d9397a
commit
42212cb865
4 files changed
+17
-3
No files matched your search
@@ -18,6 +18,11 @@ const aliases = {
|
||||
weekend: 'week', //for now...
|
||||
}
|
||||
|
||||
// units made of other units
|
||||
const multiples = {
|
||||
fortnight: [2, 'week'],
|
||||
}
|
||||
|
||||
// half of a unit, in smaller whole units
|
||||
const halfUnits = {
|
||||
year: [6, 'month'],
|
||||
@@ -53,9 +58,14 @@ const parseShift = function (doc) {
|
||||
|
||||
// '5 weeks'
|
||||
shift.match('#Cardinal #Duration').forEach((ts) => {
|
||||
const num = ts.match('#Cardinal').numbers().get()[0]
|
||||
let num = ts.match('#Cardinal').numbers().get()[0]
|
||||
if (num && typeof num === 'number') {
|
||||
const unit = parseUnit(ts)
|
||||
let unit = parseUnit(ts)
|
||||
// '1 fortnight' is 2 weeks
|
||||
if (Object.hasOwn(multiples, unit)) {
|
||||
num *= multiples[unit][0]
|
||||
unit = multiples[unit][1]
|
||||
}
|
||||
if (knownUnits[unit] === true) {
|
||||
result[unit] = isNegative ? num * -1 : num
|
||||
}
|
||||
|
||||
@@ -156,6 +156,8 @@ test('date-parse :', function (t) {
|
||||
['in 1 year', '2020-02-02T00:00:00.000Z'],
|
||||
['3 days ago', '2019-01-30T00:00:00.000Z'],
|
||||
['2 weeks ago', '2019-01-19T00:00:00.000Z'],
|
||||
['in a fortnight', '2019-02-16T00:00:00.000Z'],
|
||||
['1 fortnight ago', '2019-01-19T00:00:00.000Z'],
|
||||
['1 month ago', '2019-01-02T00:00:00.000Z'],
|
||||
['1 year ago', '2018-02-02T00:00:00.000Z'],
|
||||
['at 4pm', '2019-02-02T16:00:00.000Z'],
|
||||
|
||||
Reference in new issue
Block a user