mirror of
https://github.com/ckaczor/HomeMonitor.git
synced 2026-02-16 10:58:32 -05:00
Initial commit of calendar service
This commit is contained in:
29
Calendar/Service/src/events/event.ts
Normal file
29
Calendar/Service/src/events/event.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { HolidaysTypes } from 'date-holidays';
|
||||
import { DateTime, Interval } from 'luxon';
|
||||
|
||||
export class Event {
|
||||
name: string;
|
||||
date: DateTime;
|
||||
type: HolidaysTypes.HolidayType;
|
||||
durationUntil: {
|
||||
days: number;
|
||||
hours: number;
|
||||
minutes: number;
|
||||
seconds: number;
|
||||
} | null;
|
||||
|
||||
constructor(holiday: HolidaysTypes.Holiday, timezone: string) {
|
||||
this.name = holiday.name;
|
||||
this.date = DateTime.fromFormat(holiday.date, 'yyyy-MM-dd HH:mm:ss', { zone: timezone });
|
||||
this.type = holiday.type;
|
||||
|
||||
const duration = Interval.fromDateTimes(DateTime.now(), this.date).toDuration(['days', 'hours', 'minutes', 'seconds']);
|
||||
|
||||
this.durationUntil = !duration.isValid ? null : {
|
||||
days: duration.days,
|
||||
hours: duration.hours,
|
||||
minutes: duration.minutes,
|
||||
seconds: Math.round(duration.seconds)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user