Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('transfers UTC', function() {
let calendar = new Calendar(document.createElement('div'), {
plugins: [ DayGridPlugin ],
events: [ { start: '2018-09-05T12:00:00', end: '2018-09-05T18:00:00' } ],
timeZone: 'UTC'
})
let event = calendar.getEvents()[0]
var startMom = toMoment(event.start, calendar)
var endMom = toMoment(event.end, calendar)
expect(startMom.format()).toEqual('2018-09-05T12:00:00Z')
expect(endMom.format()).toEqual('2018-09-05T18:00:00Z')
})
it('transfers local', function() {
let calendar = new Calendar(document.createElement('div'), {
plugins: [ DayGridPlugin ],
events: [ { start: '2018-09-05T12:00:00', end: '2018-09-05T18:00:00' } ],
timeZone: 'local'
})
let event = calendar.getEvents()[0]
var startMom = toMoment(event.start, calendar)
var endMom = toMoment(event.end, calendar)
expect(startMom.toDate()).toEqualLocalDate('2018-09-05T12:00:00')
expect(endMom.toDate()).toEqualLocalDate('2018-09-05T18:00:00')
})
it('transfers UTC', function() {
let calendar = new Calendar(document.createElement('div'), {
plugins: [ DayGridPlugin ],
events: [ { start: '2018-09-05T12:00:00', end: '2018-09-05T18:00:00' } ],
timeZone: 'UTC'
})
let event = calendar.getEvents()[0]
var startMom = toMoment(event.start, calendar)
var endMom = toMoment(event.end, calendar)
expect(startMom.format()).toEqual('2018-09-05T12:00:00Z')
expect(endMom.format()).toEqual('2018-09-05T18:00:00Z')
})
private getMonthRangesToBeDisplayed(): DisplayedMonth[] {
let startMoment = toMoment(this.currentStart, this.calendar);
let endMoment = toMoment(this.currentEnd, this.calendar);
const numberOfMonths = endMoment.diff(startMoment, 'month');
const displayedMonths: DisplayedMonth[] = [];
for (let i = 0; i < numberOfMonths; i++) {
let intervalStart = startMoment.clone().add(i, 'month');
let intervalEnd = startMoment.clone().add(i + 1, 'month');
const monthRange: DisplayedMonth = {
intervalStart,
intervalEnd,
displayedStart: this.startOfWeek(startMoment),
displayedEnd: this.startOfWeek(intervalEnd).add(7, "day"),
displayedWeeks: this.getDisplayedWeeks(intervalStart)
};
displayedMonths.push(monthRange);
}
return displayedMonths;
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;
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 this.events.filter(e => {
let eventStart = toMoment(e.start, this.calendar);
let eventEnd = e.end != null ? toMoment(e.end, this.calendar) : eventStart.clone().add(1, 'second');
return +eventEnd > +dayStart && +eventStart < +(dayEnd);
});
}
private getMonthRangesToBeDisplayed(): DisplayedMonth[] {
let startMoment = toMoment(this.currentStart, this.calendar);
let endMoment = toMoment(this.currentEnd, this.calendar);
const numberOfMonths = endMoment.diff(startMoment, 'month');
const displayedMonths: DisplayedMonth[] = [];
for (let i = 0; i < numberOfMonths; i++) {
let intervalStart = startMoment.clone().add(i, 'month');
let intervalEnd = startMoment.clone().add(i + 1, 'month');
const monthRange: DisplayedMonth = {
intervalStart,
intervalEnd,
displayedStart: this.startOfWeek(startMoment),
displayedEnd: this.startOfWeek(intervalEnd).add(7, "day"),
displayedWeeks: this.getDisplayedWeeks(intervalStart)
};
displayedMonths.push(monthRange);
}
return displayedMonths;
}