diff --git a/src/Event.tsx b/src/Event.tsx index 6ce88df..6fc6c03 100644 --- a/src/Event.tsx +++ b/src/Event.tsx @@ -1,7 +1,36 @@ import * as React from 'react'; +import * as moment from 'moment'; import * as ICAL from 'ical.js'; +function formatDateRange(start: ICAL.Time, end: ICAL.Time) { + const mStart = moment(start.toJSDate()); + const mEnd = moment(end.toJSDate()); + let strStart; + let strEnd; + + const allDayFormat = 'dddd, LL'; + const fullFormat = 'LLLL'; + + // All day + if (start.isDate) { + if (mEnd.diff(mStart, 'days', true) === 1) { + return mStart.format(allDayFormat); + } else { + strStart = mStart.format(allDayFormat); + strEnd = mEnd.clone().subtract(1, 'day').format(allDayFormat); + } + } else if ((mStart.day === mEnd.day) && (mEnd.diff(mStart, 'days', true) < 1)) { + strStart = mStart.format(fullFormat); + strEnd = mEnd.format('LT'); + } else { + strStart = mStart.format(fullFormat); + strEnd = mEnd.format(fullFormat); + } + + return strStart + ' - ' + strEnd; +} + class Event extends React.Component { props: { event?: ICAL.Event, @@ -12,9 +41,15 @@ class Event extends React.Component { throw Error('Event should be defined!'); } + (window as any).me = this.props.event; + return (