Added Event class, which represents a single event in the calendar

This commit is contained in:
Franco Speziali 2022-03-16 08:39:09 +01:00
parent e0ca747cf2
commit c2b6bb6b8e
2 changed files with 32 additions and 0 deletions

17
src/Events/Event.ts Normal file
View File

@ -0,0 +1,17 @@
import { Event as _Event } from "../types";
export default class Event implements _Event {
date: Date;
title: string;
text?: string;
icon?: string;
backgroundColor?: string;
constructor({ date, title, text, icon, backgroundColor }) {
this.date = new Date(date);
this.title = title;
this.text = text;
this.icon = icon;
this.backgroundColor = backgroundColor;
}
}

15
src/Events/index.ts Normal file
View File

@ -0,0 +1,15 @@
import Event from "./Event";
export default class Events {
sortedEvents: Event[];
constructor(events: Event[]) {
this.sortedEvents = this.processEvents(events);
}
processEvents(events): Event[] {
const _events = events.map((event) => new Event(event));
return _events.sort((a, b) => a.date - b.date);
}
}