Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(Interval.before(DateTime.utc(), Duration.fromObject({ year: 1 })): Interval);
(Interval.before(DateTime.utc(), { year: 1 }): Interval);
(Interval.before(DateTime.utc(), 1231234): Interval);
(Interval.before(
{ year: 2017, month: 1 },
Duration.fromObject({ year: 1 })
): Interval);
(Interval.before({ year: 2017, month: 1 }, { year: 1 }): Interval);
(Interval.before({ year: 2017, month: 1 }, 123123): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1, foo: "bar" }, { year: 1 }): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1 }, { year: 1, foo: "bar" }): Interval);
(Interval.fromDateTimes(DateTime.utc(), DateTime.utc()): Interval);
(Interval.fromDateTimes(DateTime.utc(), { year: 2017, month: 1 }): Interval);
(Interval.fromDateTimes({ year: 2016, month: 1 }, DateTime.utc()): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
// $ExpectError
{ year: 2016, month: 1, foo: 'bar' },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
// $ExpectError
{ year: 2017, month: 1, foo: 'bar' }
): Interval);
(Interval.before(DateTime.utc(), { year: 1 }): Interval);
(Interval.before(DateTime.utc(), 1231234): Interval);
(Interval.before(
{ year: 2017, month: 1 },
Duration.fromObject({ year: 1 })
): Interval);
(Interval.before({ year: 2017, month: 1 }, { year: 1 }): Interval);
(Interval.before({ year: 2017, month: 1 }, 123123): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1, foo: "bar" }, { year: 1 }): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1 }, { year: 1, foo: "bar" }): Interval);
(Interval.fromDateTimes(DateTime.utc(), DateTime.utc()): Interval);
(Interval.fromDateTimes(DateTime.utc(), { year: 2017, month: 1 }): Interval);
(Interval.fromDateTimes({ year: 2016, month: 1 }, DateTime.utc()): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
// $ExpectError
{ year: 2016, month: 1, foo: 'bar' },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
// $ExpectError
{ year: 2017, month: 1, foo: 'bar' }
): Interval);
(Interval.fromISO("23;lkj1"): Interval);
(Interval.before(DateTime.utc(), Duration.fromObject({ year: 1 })): Interval);
(Interval.before(DateTime.utc(), { year: 1 }): Interval);
(Interval.before(DateTime.utc(), 1231234): Interval);
(Interval.before(
{ year: 2017, month: 1 },
Duration.fromObject({ year: 1 })
): Interval);
(Interval.before({ year: 2017, month: 1 }, { year: 1 }): Interval);
(Interval.before({ year: 2017, month: 1 }, 123123): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1, foo: "bar" }, { year: 1 }): Interval);
// $ExpectError
(Interval.before({ year: 2017, month: 1 }, { year: 1, foo: "bar" }): Interval);
(Interval.fromDateTimes(DateTime.utc(), DateTime.utc()): Interval);
(Interval.fromDateTimes(DateTime.utc(), { year: 2017, month: 1 }): Interval);
(Interval.fromDateTimes({ year: 2016, month: 1 }, DateTime.utc()): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
// $ExpectError
{ year: 2016, month: 1, foo: 'bar' },
{ year: 2017, month: 1 }
): Interval);
(Interval.fromDateTimes(
{ year: 2016, month: 1 },
// $ExpectError
{ year: 2017, month: 1, foo: 'bar' }
): Interval);
if (s.invalid === null && b.invalid === null) {
this.initialize(
interval,
this.props.searchQuery,
this.props.slug
);
}
} else {
// This is the default state
const s = DateTime.fromObject({ year: 2010, month: 1 }).startOf(
'month'
);
const b = DateTime.fromObject({ year: 2019, month: 12 }).endOf(
'month'
);
const interval = Interval.fromDateTimes(s, b);
this.initialize(interval, null);
}
return null;
}
const rawInterval = Interval.fromDateTimes(s, b);
const interval = moreThanOne
? rawInterval.divideEqually(5)[3]
: rawInterval;
_this.initialize(
interval,
this.props.searchQuery,
this.props.slug
);
}
});
} else if (this.props.hasInterval) {
const s = DateTime.fromISO(this.props.start);
const b = DateTime.fromISO(this.props.before);
const interval = Interval.fromDateTimes(s, b);
if (s.invalid === null && b.invalid === null) {
this.initialize(
interval,
this.props.searchQuery,
this.props.slug
);
}
} else {
// This is the default state
const s = DateTime.fromObject({ year: 2010, month: 1 }).startOf(
'month'
);
const b = DateTime.fromObject({ year: 2019, month: 12 }).endOf(
'month'
);
const interval = Interval.fromDateTimes(s, b);
it('Is Between', () => {
const m = moment('2010-10-20').isBetween('2010-10-19', '2010-10-25');
const d = date.isWithinInterval(new Date(2010, 9, 20), {
start: new Date(2010, 9, 19),
end: new Date(2010, 9, 25),
});
const day = dayjs('2010-10-20').isBetween('2010-10-19', '2010-10-25'); //plugin
const luxon = Interval.fromDateTimes(
DateTime.fromISO('2010-10-19'),
DateTime.fromISO('2010-10-25')
).contains(DateTime.fromISO('2010-10-20'));
expect(m).toBeTruthy();
expect(d).toBeTruthy();
expect(day).toBeTruthy();
expect(luxon).toBeTruthy();
});
function getAttemptDurationString(attempt) {
const start =
attempt.attemptStartedTime &&
DateTime.fromMillis(attempt.attemptStartedTime);
const end = attempt.attemptCompletedTime
? DateTime.fromMillis(attempt.attemptCompletedTime)
: DateTime.utc();
if (start && end) {
return getDurationString(
Interval.fromDateTimes(start, end || DateTime.utc()).toDuration([
'days',
'hours',
'minutes',
'seconds',
]),
);
} else {
return 'N/A';
}
}
async getDatedMetrics(start: DateTime, end: DateTime): Promise {
start = start.startOf("day");
end = end.startOf("day");
if (end < start) {
const t = end;
end = start;
start = t;
}
const interval = Interval.fromDateTimes(start, end);
const dates = _.concat(interval.splitBy({ days: 1 }).map((i) => i.start), [end]);
const ret: MetricDayRange = {};
for (let date of dates) {
const ymd = date.toFormat(LUXON_YMD);
const keys = [
`metrics/processed/${ymd}`,
`metrics/errored/${ymd}`,
`metrics/completed/${ymd}`,
`metrics/died/${ymd}`
];
const resp = await this.asyncRedis.mget(...keys);
ret[ymd] = {
processed: parseInt(resp[0] || "0", 10),
errored: parseInt(resp[1] || "0", 10),
setPosition(dt) {
const newInterval = Interval.fromDateTimes(
this.state.interval.start,
DateTime.fromISO(dt)
);
const perc = Math.floor(
100 *
(newInterval.length('seconds') /
this.state.interval.length('seconds'))
);
this.setState({ slide: perc });
}