Skip to content

Commit

Permalink
✨ Allow all day events spanning multiple days
Browse files Browse the repository at this point in the history
  • Loading branch information
lachenmayer committed May 28, 2019
1 parent d10afa6 commit 34e70d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
12 changes: 12 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ test("generate an all day google link", () => {
);
});

test("generate a multi day google link", () => {
const link = google({
title: "Birthday party",
start: "2019-12-29",
end: "2020-01-12",
allDay: true
});
expect(link).toBe(
"https://calendar.google.com/calendar/render?action=TEMPLATE&text=Birthday%20party&details=&location=&trp=&dates=20191229%2F20200112"
);
});

test("generate a google link with guests", () => {
const link = google({
title: "Birthday party",
Expand Down
24 changes: 13 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ dayjs.extend(utc);

export const eventify = (event: CalendarEvent) => {
event.start = dayjs(event.start).toDate();
if (event.duration && event.duration.length && !event.end) {
const duration = Number(event.duration[0]);
const unit = event.duration[1];
event.end = dayjs(event.start)
.add(duration, unit)
.toDate();
}
if (event.allDay) {
event.end = dayjs(event.start)
.add(1, "day")
.toDate();
if (event.end == null) {
if (event.duration && event.duration.length) {
const duration = Number(event.duration[0]);
const unit = event.duration[1];
event.end = dayjs(event.start)
.add(duration, unit)
.toDate();
}
if (event.allDay) {
event.end = dayjs(event.start)
.add(1, "day")
.toDate();
}
}
return event;
};
Expand Down

0 comments on commit 34e70d3

Please sign in to comment.