This only happens in Safari, and I have tracked it down to what line, but everything I've tried to do to get around it does not help.
It works just fine in Chrome and Firefox.
It's this line that causes the issue
this.preppedEvents[tmpDate.getFullYear()][tmpDate.getMonth()]
Initially I thought that maybe it was when I explicitly set a value to the 0 index, but i'm not convinced that's the solution.
The error I receive is, "TypeError undefined is not an object"
I've tried initializing the preppedEvents object with dummy data before updating it. Nothing seems to help.
public constructor(private _jKiruService: JKiruService) { }
public resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this._jKiruService
.addRequest('Calendar', 'getDisplayable').runl();
}
}
@Component({
selector: 'app-learn-calendar',
templateUrl: './learn-calendar.component.html',
styleUrls: ['./learn-calendar.component.scss']
})
export class LearnCalendarComponent implements OnInit, OnDestroy {
public preppedEvents = [];
private _events = [];
private _subscriptions: Subscription[] = [];
constructor(
private _route: ActivatedRoute,
private _jKiruService: JKiruService,
private _subscriber: SubscriptionService
) {
this._subscriptions = this._subscriber.getSubscriber();
}
ngOnInit() {
this._subscriptions['resolver'] = this._route.params.subscribe((res) => {
if (res) {
this._events = this._jKiruService.pull('calendar_event', true);
}
});
this.prepEvents();
}
public prepEvents() {
const currentDateObj = new Date();
// Initial Loop
for (let y = currentDateObj.getFullYear(); y < currentDateObj.getFullYear() + 2; y++) {
this.preppedEvents[y] = [];
for (let i = 0; i < 12; i++) {
this.preppedEvents[y][i] = { month: OutwardDate.decodeMonth(i), events: [] };
}
}
for (const event of this._events) {
for (const day of event.events) {
/**
* important to note:
* because of 0 index of month place, we need to add 1 to the display version
* also need to format date from 2020-02-15 to 2020,02,15 to get accurate new date object
*/
let tmpDate = new Date(day.day.replace(/-/g, ','));
if (typeof this.preppedEvents[tmpDate.getFullYear()][tmpDate.getMonth()] === 'undefined' || this.preppedEvents[tmpDate.getFullYear()][tmpDate.getMonth()] === 'undefined' ) {
return;
}
let monthDay = (tmpDate.getDate() < 10 ? '0' : '') + tmpDate.getDate();
this.preppedEvents[tmpDate.getFullYear()][tmpDate.getMonth()].events.push({
title: event.title,
description: event.description,
day: '' + (tmpDate.getMonth() + 1) + '/' + (monthDay) + '/' + tmpDate.getFullYear(), // we only need to add the 1 here to the month because its for display purposes, otherwise its index is correct
start_time: day.start,
end_time: day.end,
time_description: day.description.replace(/<br>/g, ' ')
});
}
}
for (let y = currentDateObj.getFullYear(); y < currentDateObj.getFullYear() + 2; y++) {
for (let i = 0; i < 12; i++) {
this.preppedEvents[y][i].events = qsort2(this.preppedEvents[y][i].events, ['day', 'start_time']);
}
}
}
}
Here's a screenshot of the error and where it appears
**** updated with a link ****
Here's a stackblitz link, make sure you are in Safari so the error will reproduce https://stackblitz.com/edit/angular-ya3gzk
