How to use the chrono-node.parse 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 glennjones / text-autolinker / lib / autolinker.js View on Github external
function addTimeTags(obj, options) {
	var data,
		iso,
		cn = options.className,
		restictedWords = ['today', 'tomorrow', 'yesterday'],
		tag = '',
		date = '',
		x = 0,
		i;


	if (options.publishedDate) {
		data = chrono.parse(options.text, options.publishedDate);
	} else {
		data = chrono.parse(options.text);
	}

	//console.log(JSON.stringify(data))

	if (data.length > -1) {
		i = data.length;
		while (x < i) {

			date = data[x].startDate;

			// do not use: 
			// impliedComponents for day, month
			// text containing today, tomorrow, yesterday
github zeke / remind-me / lib / parse.js View on Github external
patterns.some(function (_) {
    var pattern = easyPattern(_)
    if (pattern.test(input)) {
      result = pattern.match(input)

      // special case for trailing tomorrow
      if (!result.time && _.match(/tomorrow$/i)) {
        result.time = chrono.parse('tomorrow')[0].start.date()
      }

      if (result.interval) {
        result.interval = dateparser(result.interval).value
        result.time = Date.now() + result.interval
      }

      // undo the regex 'to' hack
      result.task = result.task.replace(/__to__/ig, ' to ')

      if (typeof result.time === 'string') {
        result.time = chrono.parse(result.time)[0].start.date()
      }

      return true
    }
github glennjones / text-autolinker / lib / autolinker.js View on Github external
function addTimeTags(obj, options) {
	var data,
		iso,
		cn = options.className,
		restictedWords = ['today', 'tomorrow', 'yesterday'],
		tag = '',
		date = '',
		x = 0,
		i;


	if (options.publishedDate) {
		data = chrono.parse(options.text, options.publishedDate);
	} else {
		data = chrono.parse(options.text);
	}

	//console.log(JSON.stringify(data))

	if (data.length > -1) {
		i = data.length;
		while (x < i) {

			date = data[x].startDate;

			// do not use: 
			// impliedComponents for day, month
			// text containing today, tomorrow, yesterday

			if (!data[x].start.impliedComponents) {
				data[x].start.impliedComponents = [];
github SerjoPepper / delorean_bot / src / node_modules / bot.js View on Github external
function getNotifyOptions (text, timezone) {
  var res;
  var resMoment;
  var options = {
    expireOffset: null, // expire offset in seconds
    unixTimestamp: null,
    text: text
  };
  try {
    res = chrono.parse(text);
  } catch (e) {
    console.error(e, e.stack);
    return null;
  }

  if (!res || !res.length) {
    return null;
  }

  res = res[res.length - 1];
  resDate = chrono.parseDate(res.text);

  if (res.tags.RUDeadlineFormatParser || res.tags.ENDeadlineFormatParser) {
    resMoment = moment(resDate);
    options.unixTimestamp = resMoment.unix();
    options.expireOffset = resMoment.diff(new Date, 'seconds');
github keystonejs / keystone / packages / arch / packages / day-picker / src / TextDayTimePicker.js View on Github external
function parseDate(value) {
  let [parsedDate] = chrono.parse(value);
  if (parsedDate === undefined) {
    return null;
  }
  let dateMoment = parsedDateToMoment(parsedDate);
  return dateMoment.toISOString(
    // passing true here keeps the offset in the iso string rather than
    // convert it to UTC which is the default to align with native JS Dates
    true
  );
}
github denouche / virtual-assistant / src / feature / statistics / statistics.js View on Github external
Promise.all(futureStats)
            .then((dataArray) => {
                dataArray = _(dataArray)
                    .sortBy([(o) => {
                        return o.data.length;
                    }])
                    .reverse()
                    .value();
                dataArray.forEach((data) => {
                    let byUser = _.countBy(data.data, 'event.userId');
                    toSend.push(`  • ${data.name}: solicité ${data.data.length} fois par ${_.keys(byUser).length} utilisateurs différents`);
                });
                this.send(toSend);
            });

        var results = chrono.parse(text);
        debug(results);

        if(results.length > 0) {
            if(results[0].start) {
                debug(results[0].start.date());
            }
            if(results[0].end) {
                debug(results[0].end.date());
            }
        }

        this.wait();
    }
github CVCEeu-dh / histograph / scripts / dates.js View on Github external
var q = async.queue(function (resource, nextResource) {
        var context = resource.name || resource.title;
        context = context || resource.caption_fr || resource.caption_en;
        
        console.log(resource.id, ' remaining', q.length())
        console.log('context', context)
        if(!context) {
          nextResource();
          return;
        }
        
        var languages = langdetect.detect(context);
        
        var language = languages.length? langdetect.detect(context).shift().shift() : 'en',
            dates =  chrono.parse(context);

        console.log(context, language, resource.id, 're', q.length())
        
        if(!dates.length) {
          helpers.reconcileHumanDate(context, language, function(err, dates){
            if(err || isNaN(dates.start_time)) {
              remainings.push(resource);
              nextResource();
              return;
            }
            resource = _.assign(resource, {
              date: dates.text_date,
              start_date: dates.start_date,
              start_time: dates.start_time,
              end_date: dates.end_date,
              end_time: dates.end_time
github livinglab / openlab / wp-content / plugins / the-events-calendar / common / src / modules / utils / date.js View on Github external
export const labelToDate = ( label ) => {
	const [ parsed ] = chrono.parse( label );
	const dates = {
		start: null,
		end: null,
	};
	if ( parsed ) {
		const { start, end } = parsed;
		dates.start = start ? momentUtil.toDateTime( momentUtil.toMoment( start.date() ) ) : null;
		dates.end = end ? momentUtil.toDateTime( momentUtil.toMoment( end.date() ) ) : null;
	}
	return dates;
};
github nylas-mail-lives / nylas-mail / src / date-utils.es6 View on Github external
parseDateString(dateLikeString) {
    const parsed = chrono.parse(dateLikeString)
    const gotTime = {start: false, end: false};
    const gotDay = {start: false, end: false};
    const now = moment();
    const results = {start: moment(now), end: moment(now), leftoverText: dateLikeString};
    for (const item of parsed) {
      for (const val of ['start', 'end']) {
        if (!(val in item)) {
          continue;
        }
        const {day: knownDay, weekday: knownWeekday, hour: knownHour} = item[val].knownValues;
        const {year, month, day, hour, minute} = Object.assign(item[val].knownValues, item[val].impliedValues)
        if (!gotTime[val] && knownHour) {
          gotTime[val] = true;
          results[val].minute(minute)
          results[val].hour(hour)

chrono-node

A natural language date parser in Javascript

MIT
Latest version published 2 months ago

Package Health Score

83 / 100
Full package analysis

Similar packages