From 1524600e4b2f201ed8299e5c3d538f78bffc522d Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 13 Dec 2017 14:38:00 +0000 Subject: [PATCH] In iCal, all day events are until the end date not including Adjust accordingly, and add some basic validation. --- src/EventEdit.tsx | 25 +++++++++++++++++++++---- src/ical.js.d.ts | 7 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/EventEdit.tsx b/src/EventEdit.tsx index 3551f9f..1921923 100644 --- a/src/EventEdit.tsx +++ b/src/EventEdit.tsx @@ -48,11 +48,18 @@ class EventEdit extends React.Component { if (this.props.event !== undefined) { const event = this.props.event; + const allDay = event.startDate.isDate; + let endDate = event.endDate.clone(); + + if (allDay) { + endDate.adjust(-1, 0, 0, 0); + } + this.state.uid = event.uid; this.state.title = event.title ? event.title : ''; - this.state.allDay = event.startDate.isDate; + this.state.allDay = allDay; this.state.start = event.startDate.toString(); - this.state.end = event.endDate.toString(); + this.state.end = endDate.toString(); this.state.location = event.location ? event.location : ''; this.state.description = event.description ? event.description : ''; } else { @@ -105,6 +112,16 @@ class EventEdit extends React.Component { if ((this.state.start === '') || (this.state.end === '')) { return; } + const startDate = ICAL.Time.fromString(this.state.start); + let endDate = ICAL.Time.fromString(this.state.end); + + if (startDate.compare(endDate) >= 0) { + return; + } + + if (this.state.allDay) { + endDate.adjust(1, 0, 0, 0); + } let event = (this.props.event) ? this.props.event.clone() @@ -113,8 +130,8 @@ class EventEdit extends React.Component { ; event.uid = this.state.uid; event.summary = this.state.title; - event.startDate = ICAL.Time.fromString(this.state.start); - event.endDate = ICAL.Time.fromString(this.state.end); + event.startDate = startDate; + event.endDate = endDate; event.location = this.state.location; event.description = this.state.description; diff --git a/src/ical.js.d.ts b/src/ical.js.d.ts index b8c4575..1d30e97 100644 --- a/src/ical.js.d.ts +++ b/src/ical.js.d.ts @@ -70,6 +70,13 @@ declare module 'ical.js' { isDate?: boolean }); + compare(aOther: Time): number; + + clone(): Time; + + adjust( + aExtraDays: number, aExtraHours: number, aExtraMinutes: number, aExtraSeconds: number, aTimeopt?: Time): void; + fromJSDate(aDate: Date | null, useUTC: boolean): void; toJSDate(): Date;