diff options
Diffstat (limited to 'desktop/island/calendar/Cal.js')
| -rw-r--r-- | desktop/island/calendar/Cal.js | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/desktop/island/calendar/Cal.js b/desktop/island/calendar/Cal.js index 6cf492d..6ec7bb3 100644 --- a/desktop/island/calendar/Cal.js +++ b/desktop/island/calendar/Cal.js @@ -112,14 +112,28 @@ function stepTime(s, minutes) { return pad(Math.floor(m / 60)) + ":" + pad(m % 60); } -// A new event on `day`: the next whole hour, one hour long, alarm 1h (the -// most common alarm in the live calendars). Capped at 22:00 so the end stays -// on the same day. -function newDraft(day, now, calendar) { +// A new event on `day`: the next whole hour, `minutes` long (the island's +// default event length), alarm 1h (the most common alarm in the live +// calendars). Capped at 22:00 so a short event stays on the same day. +function newDraft(day, now, calendar, minutes) { const h = Math.min(22, now.getHours() + 1); - return { uid: "", source: "", calendar: calendar, title: "", allDay: false, - startDay: day, endDay: day, startTime: pad(h) + ":00", endTime: pad(h + 1) + ":00", - repeat: "none", until: "", alarm: "1h", location: "", notes: "", override: false }; + return withStart({ uid: "", source: "", calendar: calendar, title: "", allDay: false, + startDay: day, endDay: day, startTime: pad(h) + ":00", endTime: pad(h) + ":00", + repeat: "none", until: "", alarm: "1h", location: "", notes: "", override: false }, + pad(h) + ":00", minutes); +} + +// The draft with a new start time, as typed, the end following it `minutes` later, +// into the next day if need be. A multi-day event keeps its end: snapping it +// to the start's day would throw the other days away. +function withStart(draft, time, minutes) { + const d = Object.assign({}, draft, { startTime: time }); + const n = normTime(time); + if (!validTime(n) || d.startDay !== d.endDay) return d; + const t = +n.slice(0, 2) * 60 + +n.slice(3, 5) + (minutes > 0 ? minutes : 60); + d.endDay = addDays(d.startDay, Math.floor(t / 1440)); + d.endTime = pad(Math.floor(t % 1440 / 60)) + ":" + pad(t % 60); + return d; } // calctl's event JSON as an editor draft. `source` is the calendar the event |
