Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
}
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 = [];
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');
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
);
}
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();
}
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
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;
};
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)