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) { this.summary = json_data["summary"]; this.description = json_data["description"]; this.start = DateTime .fromISO(json_data["dtstart"]) .setLocale(navigator.language); const end = DateTime .fromISO(json_data["dtend"]) .setLocale(navigator.language); this.duration = end.diff(this.start); } public get hash(): string { const str = JSON.stringify(this); // source: https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0?permalink_comment_id=2775538#gistcomment-2775538 let hash = 0; for (let i = 0; i < str.length; i++) hash = Math.imul(31, hash) + str.charCodeAt(i) | 0; return new Uint32Array([hash])[0].toString(36); } }