2022-09-14 23:04:26 +00:00
|
|
|
import { DateTime, Duration } from "luxon";
|
|
|
|
|
|
|
|
|
|
export default class Event {
|
|
|
|
|
public summary: string;
|
|
|
|
|
public description: string;
|
|
|
|
|
public start: DateTime;
|
|
|
|
|
public duration: Duration;
|
|
|
|
|
|
|
|
|
|
public constructor(json_data: Record<string, string>) {
|
|
|
|
|
this.summary = json_data["summary"];
|
|
|
|
|
this.description = json_data["description"];
|
2022-09-15 00:40:49 +00:00
|
|
|
this.start = DateTime
|
|
|
|
|
.fromISO(json_data["dtstart"])
|
|
|
|
|
.setLocale(navigator.language);
|
|
|
|
|
const end = DateTime
|
|
|
|
|
.fromISO(json_data["dtend"])
|
|
|
|
|
.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-14 23:04:26 +00:00
|
|
|
}
|