-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (25 loc) · 809 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict'
const Chrono = require('chrono-node')
const Moment = require('moment')
// Refine MM/DD Spanish format date
const ddMMRefiner = new Chrono.Refiner();
ddMMRefiner.refine = function (text, results, opt) {
results.forEach(function (result) {
if (result.tags.ENSlashDateFormatParser) {
const match = /\b(\d{1,2})\/(\d{1,2})\b/i.exec(text)
if (match) {
const refDate = Moment(result.ref)
const day = parseInt(match[1])
const month = parseInt(match[2])
if (month < refDate.month() + 1) {
result.start.assign('year', refDate.year() + 1)
}
result.start.assign('month', month)
result.start.assign('day', day)
result.start.assign('hour', 0)
}
}
});
return results;
}
module.exports = ddMMRefiner