Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (previousBatchExists && openedBeforeNextBatch) {
// Since we know that we reopened the notifications before the next batch, the last batch
// will have ended at the last daily reset time
const lastBatchEnd = lastWeeklyReset
// Sanity check in case lastBatchStart is invalid (eg not cleared after a settings change)
if (lastBatchStart < lastBatchEnd.toDate()) {
return {
start: lastBatchStart,
end: lastBatchEnd.toDate()
};
}
}
// If you've never opened the menu before, then return the last daily batch, else
// create batch for all periods that happened since you last opened it
const startDate = lastOpened ? moment.min(oneWeekPrior, moment(lastOpened)) : oneWeekPrior
return {
start: startDate.toDate(),
end: lastWeeklyReset.toDate(),
};
}
case "realtime":
if (!lastOpened) {
// If set to realtime and never opened before (eg, you just changed the
// setting), default to the last 24 hours.
return {
start: moment().subtract(1, 'days').toDate(),
end: now
}
} else {
return {
start: lastOpened,
if (previousBatchExists && openedBeforeNextBatch) {
// Since we know that we reopened the notifications before the next batch, the last batch
// will have ended at the last daily reset time
const lastBatchEnd = lastDailyReset
// Sanity check in case lastBatchStart is invalid (eg not cleared after a settings change)
if (lastBatchStart < lastBatchEnd.toDate()) {
return {
start: lastBatchStart,
end: lastBatchEnd.toDate()
};
}
}
// If you've never opened the menu before, then return the last daily batch, else
// create batch for all periods that happened since you last opened it
const startDate = lastOpened ? moment.min(oneDayPrior, moment(lastOpened)) : oneDayPrior
return {
start: startDate.toDate(),
end: lastDailyReset.toDate(),
};
}
case "weekly": {
// Target day of the week, as an integer 0-6
const targetDayOfWeekNum = moment().day(settings.dayOfWeekGMT).day();
const lastDailyResetDayOfWeekNum = lastDailyReset.day();
// Number of days back from today's daily reset to get to a daily reset
// of the correct day of the week
const daysOfWeekDifference = ((lastDailyResetDayOfWeekNum - targetDayOfWeekNum) + 7) % 7;
const lastWeeklyReset = moment(lastDailyReset).subtract(daysOfWeekDifference, 'days');
const oneWeekPrior = moment(lastWeeklyReset).subtract(7, 'days');
render() {
const {
t, fld, classes, stixObservable,
} = this.props;
const scores = stixObservable.stixRelations.edges.map(n => n.node.score);
const expirations = stixObservable.stixRelations.edges.map(n => moment(n.node.expiration));
const weights = stixObservable.stixRelations.edges.map(n => n.node.weight
);
const minExpiration = moment.min(expirations);
return (
<div style="{{">
{t('Averages of context relations')}
{t('Confidence level')}
{t('Score')}</div>
private eventToSegments(event: EventApi): Segment[] {
let startMoment = toMoment(event.start, this.calendar);
let endMoment = event.end != null ? toMoment(event.end, this.calendar) : null;
if (event.end == null) {
let start = startMoment.clone().startOf("day").hour(8);
let end = startMoment.clone().startOf("day").hour(16);
return [new Segment(moment(start), moment(end), true, true, event)];
} else if (startMoment.day() === endMoment.day() && endMoment.valueOf() - startMoment.valueOf() < 86400000 /*day*/) {
return [new Segment(startMoment, endMoment, true, true, event)];
} else {
let segments: Segment[] = [];
let segStart = startMoment;
let segEnd = startMoment;
while (segEnd.valueOf() < endMoment.valueOf()) {
segStart = segEnd;
segEnd = moment.min(endMoment, segStart.clone().startOf("day").add(1, "day"));
segments.push(new Segment(segStart.clone(), segEnd.clone(), +segStart === +event.start, +segEnd === +event.end, event));
}
return segments;
}
}
(x) => moment.min(events.getIn([x, 'endDate']), endDate).valueOf()],
['asc', 'desc']
static min( ...datetimes ) {
return this.fromMoment(
moment.min(
this[ privateMethods.extractMomentsFromDateTimes ](
...datetimes
)
)
);
}
const positionedEvent = (eventKey, events, weekStartDate, weekEndDate) => {
const evnt = events.get(eventKey);
const eventStartDate = evnt.get('startDate');
const eventEndDate = evnt.get('endDate');
const adjStartDate = moment.max(eventStartDate, weekStartDate);
const adjEndDate = moment.min(eventEndDate, weekEndDate);
return {
id: eventKey,
span: adjEndDate.diff(adjStartDate, 'days') + 1,
start: adjStartDate.diff(weekStartDate, 'days') + 1,
startDate: adjStartDate,
endDate: adjEndDate,
moreLeft: eventStartDate < weekStartDate,
moreRight: eventEndDate > weekEndDate
};
};