2022-09-14 23:04:26 +00:00
|
|
|
import { DateTime, Duration } from "luxon";
|
|
|
|
|
|
2022-09-15 13:03:19 +00:00
|
|
|
export type EventJSONData = {
|
|
|
|
|
summary: string;
|
|
|
|
|
description: string;
|
|
|
|
|
dtstart: string;
|
|
|
|
|
dtend: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default class EventData {
|
2022-09-14 23:04:26 +00:00
|
|
|
public summary: string;
|
|
|
|
|
public description: string;
|
|
|
|
|
public start: DateTime;
|
|
|
|
|
public duration: Duration;
|
|
|
|
|
|
2022-09-15 13:03:19 +00:00
|
|
|
public constructor(json_data: EventJSONData) {
|
|
|
|
|
this.summary = json_data.summary;
|
|
|
|
|
this.description = json_data.description;
|
2022-09-15 00:40:49 +00:00
|
|
|
this.start = DateTime
|
2022-09-15 13:03:19 +00:00
|
|
|
.fromISO(json_data.dtstart)
|
2022-09-15 00:40:49 +00:00
|
|
|
.setLocale(navigator.language);
|
|
|
|
|
const end = DateTime
|
2022-09-15 13:03:19 +00:00
|
|
|
.fromISO(json_data.dtend)
|
2022-09-15 00:40:49 +00:00
|
|
|
.setLocale(navigator.language);
|
2022-09-14 23:04:26 +00:00
|
|
|
|
|
|
|
|
this.duration = end.diff(this.start);
|
|
|
|
|
}
|
2022-09-15 00:07:27 +00:00
|
|
|
|
|
|
|
|
public get hash(): string {
|
|
|
|
|
const str = JSON.stringify(this);
|
|
|
|
|
|
2022-09-15 00:25:31 +00:00
|
|
|
// source: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2775538#gistcomment-2775538
|
2022-09-15 00:07:27 +00:00
|
|
|
let hash = 0;
|
2022-09-15 00:25:31 +00:00
|
|
|
for (let i = 0; i < str.length; i++)
|
|
|
|
|
hash = Math.imul(31, hash) + str.charCodeAt(i) | 0;
|
|
|
|
|
|
2022-09-15 00:07:27 +00:00
|
|
|
return new Uint32Array([hash])[0].toString(36);
|
|
|
|
|
}
|
2022-09-15 13:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type CalendarJSONData = {
|
|
|
|
|
title: string;
|
|
|
|
|
events: Array<EventJSONData>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export class CalendarData {
|
|
|
|
|
public title: string;
|
|
|
|
|
public events: Array<EventData>;
|
|
|
|
|
|
|
|
|
|
public constructor(json_data: CalendarJSONData) {
|
|
|
|
|
this.title = json_data.title
|
|
|
|
|
|
|
|
|
|
this.events = [];
|
|
|
|
|
for (const event_data of json_data.events) {
|
|
|
|
|
this.events.push(new EventData(event_data))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|