Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// $ExpectError
DateTime.fromSQL();
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { foo: "bar" });
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { zone: 2 });
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { locale: 2 });
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { setZone: "yes" });
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { outputCalendar: 2 });
// $ExpectError
DateTime.fromSQL("12/15/2017, 12:47:25 PM", { numberingSystem: 2 });
var date: DateTime = DateTime.fromFormat(
'12/15/2017, 12:47:25 PM',
'dd/MM/yyyy h:mm:ss a'
);
DateTime.fromFormat('12/15/2017, 12:47:25 PM', 'dd/MM/yyyy h:mm:ss a', {});
DateTime.fromFormat('12/15/2017, 12:47:25 PM', 'dd/MM/yyyy h:mm:ss a', {
zone: 'America/Chicago',
});
DateTime.fromFormat('12/15/2017, 12:47:25 PM', 'dd/MM/yyyy h:mm:ss a', {
zone: new CustomZone(),
});
DateTime.fromFormat('12/15/2017, 12:47:25 PM', 'dd/MM/yyyy h:mm:ss a', {
locale: 'en-US',
});
DateTime.fromFormat('12/15/2017, 12:47:25 PM', 'dd/MM/yyyy h:mm:ss a', {
zone: 'America/Chicago',
setZone: true,
function processEvent (
dwd: string | number, event: CalendarioEvent, date:
DateTime, data: ProcessedCalendarioEvents, options: CalendarioOptions
): ProcessedCalendarioEvents {
if (!data[dwd]) {
data[dwd] = []
}
let repeater: string
const _edt = event.repeat ?
(event.endDate ? DateTime.fromFormat(event.endDate, options.format, {locale: options.parserLocale})
: date.plus({ years: 100 }) ) : date
if (!event.repeat) repeater = 'SINGLE'
else if (event.repeat === 'YEARLY' || event.repeat === 'MONTHLY') repeater = event.repeat
else if (event.repeat.split(/[,\s]+/).length < 7) repeater = 'WEEKLY'
else if (event.repeat.split(/[,\s]+/).length === 7) repeater = 'INTERVAL'
data[dwd].push({
...event,
...{
dates: [date.startOf('day'), _edt.startOf('day')],
generator: repeaters[repeater]
}
})
return data
const _parseDate = (date, time) => {
let text = date
let format = `yyyy-MM-dd`
if (time) {
text += ` ${time}`
format += ` HH:mm`
}
return DateTime.fromFormat(text, format, { zone: timezone }).toJSDate()
}
function fromInternalDateFormat(date) {
return DateTime.fromFormat(date, internalDateFormat).toLocal();
}
date() {return DateTime.fromFormat(this.datestring || '', 'yyyy-M-d');}
previousCalendarRanges => {
const [baseStart, baseEnd] = previousCalendarRanges[0];
return [
DateTime.fromFormat(baseStart, 'yyyy-MM-dd')
.minus({ years: 1 })
.toFormat('yyyy-MM-dd'),
DateTime.fromFormat(baseEnd, 'yyyy-MM-dd')
.minus({ years: 1 })
.toFormat('yyyy-MM-dd'),
];
}
),
public parse(value: string, formatString: string) {
if (value === "") {
return null;
}
return DateTime.fromFormat(value, formatString);
}
export const fromViewFormatToLuxon = (value: ?string, dateFormat: ?string) => {
if (value) {
value = DateTime.fromFormat(value, dateFormat || DATE_FORMAT);
} else {
value = null;
}
return value;
};