How to use the chrono-node.Parser function in chrono-node

To help you get started, we’ve selected a few chrono-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shalvah / RemindMeOfThisTweet / src / timeparser.js View on Github external
}

    resultWithDate.start.imply('hour', resultWithTime.start.get('hour'));
    resultWithDate.start.imply('minute', resultWithTime.start.get('minute'));
    resultWithDate.start.imply('meridiem', resultWithTime.start.get('meridiem'));
    resultWithDate.start.imply('timezoneOffset', resultWithTime.start.get('timezoneOffset'));

    resultWithTime.start.imply('weekday', resultWithDate.start.get('weekday'));
    resultWithTime.start.imply('day', resultWithDate.start.get('day'));
    resultWithTime.start.imply('month', resultWithDate.start.get('month'));
    resultWithTime.start.imply('year', resultWithDate.start.get('year'));

    return results;
};

const hrsMinsParser = new chrono.Parser();
hrsMinsParser.pattern = () => /(\d+)\s*hrs?(\s+(\d+)\s*min(s|ute|utes)?)?/i; // Match a pattern like "in 22hrs (30 mins)"
hrsMinsParser.extract = (text, ref, match, opt) => {
    let dateMoment = require('moment')(ref);
    dateMoment = dateMoment.add(match[1], 'hours');
    dateMoment = dateMoment.add(match[3], 'minutes');
    return new chrono.ParsedResult({
        ref: ref,
        text: match[0],
        index: match.index,
        start: {
            hour: dateMoment.hour(),
            minute: dateMoment.minute(),
            second: dateMoment.second(),
            day: dateMoment.date(),
            month: dateMoment.month() + 1,
            year: dateMoment.year(),

chrono-node

A natural language date parser in Javascript

MIT
Latest version published 4 months ago

Package Health Score

78 / 100
Full package analysis

Similar packages