Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseDate(dateString: string, forward: boolean = false) {
if (!dateString || dateString.trim().length === 0) {
return undefined;
}
console.log(dateString);
const parsed = chrono.parseDate(dateString, new Date(), {
forwardDate: forward
});
console.log(parsed);
return parsed;
// We always use "start" because we're not actually trying to parse a date range out
// of natural text
// if (!parsed || parsed.length === 0 || !parsed[0].start) {
// return undefined;
// }
// return parsed[0].start.date();
}
return function ($) {
let value = rule($)
if (!value) return
// remove whitespace for easier parsing
value = value.trim()
// convert isodates to restringify, because sometimes they are truncated
if (isIso(value)) return new Date(value).toISOString()
// try to parse with the built-in date parser
const native = new Date(value)
if (!isNaN(native.getTime())) return native.toISOString()
// try to parse a complex date string
const parsed = chrono.parseDate(value)
if (parsed) return parsed.toISOString()
}
}
parsePlainTextDate({ isStartDate }) {
const stateKey = isStartDate ? 'startDateText' : 'endDateText'
const dateState = isStartDate
? this.state.startDateText
: this.state.endDateText
const nlpDate = chrono.parseDate(dateState)
analytics.trackEvent({
category: isStartDate ? 'Overview start date' : 'Overview end date',
action: nlpDate ? 'Successful NLP query' : 'Unsuccessful NLP query',
})
processEvent({
type: isStartDate
? EVENT_NAMES.DATEPICKER_NLP_START_DATE
: EVENT_NAMES.DATEPICKER_NLP_END_DATE,
})
// Get the time from the NLP query, if it could be parsed
if (nlpDate != null) {
return nlpDate.getTime()
}
errorMessage() {
if (_.get(this, 'args.validate')) {
const validationError = getValidationError(this.timeValue, this.args.validate, this.$store, this.name),
parsed = parseNaturalDate(this.timeValue);
if (validationError) {
return validationError;
} else if (!parsed && !isEmpty(this.timeValue)) {
// only display the time parsing error if the timepicker has data in it
return `${this.help} (Please enter a valid time)`;
}
}
},
isInvalid() {
expect(github.issues.edit).toHaveBeenCalledWith({
number: 2,
owner: 'baxterthehacker',
repo: 'public-repo',
labels: [{
url: 'https://api.github.com/repos/baxterthehacker/public-repo/labels/bug',
name: 'bug',
color: 'fc2929'
},
'reminder']
})
const params = {
who: 'baxterthehacker',
what: 'check the spinaker',
when: chrono.parseDate('July 1, 2017 9:00am')
}
expect(github.issues.edit).toHaveBeenCalledWith({
owner: 'baxterthehacker',
repo: 'public-repo',
number: 2,
body: `hello world\n\n`
})
expect(github.issues.createComment).toHaveBeenCalledWith({
number: 2,
owner: 'baxterthehacker',
repo: 'public-repo',
body: '@baxterthehacker set a reminder for **07/01/2017**'
})
})
update(val) {
const parsed = parseNaturalDate(val);
if (parsed) {
this.$emit('update', dateFormat(parsed, 'HH:mm'));
}
},
disableInput() {
public tryParseDateString(input:number | string):number {
let startDate:Date = chrono.parseDate(input);
if (startDate === null){
logger.fatal("Bailing out, couldn't interpret scenario file start time", "start:", input);
}
else {
return startDate.getTime();
}
}
export default function extractTimeFiltersFromQuery(query) {
const matchedBefore = query.match(BEFORE_REGEX)
const matchedAfter = query.match(AFTER_REGEX)
let startDate
let endDate
if (matchedBefore) {
const parsedDate = chrono.parseDate(matchedBefore[1])
endDate = parsedDate && parsedDate.getTime()
}
if (matchedAfter) {
const parsedDate = chrono.parseDate(matchedAfter[1])
startDate = parsedDate && parsedDate.getTime()
}
const extractedQuery = query
.replace(BEFORE_REGEX, '')
.replace(AFTER_REGEX, '')
.trim()
return {
startDate,
endDate,
query: extractedQuery,
}
}
schedule(task, time) {
let datedTask = Object.assign({expireTime: this.db.r.epochTime(chrono.parseDate(time, Date.now()).getTime() / 1000)}, task);
this.db.r.table("taskQueue").insert(datedTask).run();
}
tryParseDateString(input) {
let startDate = chrono.parseDate(input);
if (startDate === null) {
logger.fatal("Bailing out, couldn't interpret scenario file start time", "start:", input);
}
else {
return startDate.getTime();
}
}
dataDir() {