@@ -11,6 +11,8 @@ const ics = require('ics')
1111
1212type AddToCalendarProps = {
1313 eventDate : EventDateType
14+ startDateTime : Date
15+ endDateTime : Date
1416 location ?: string
1517 title : string
1618}
@@ -50,25 +52,30 @@ const createICS = (eventData: ICSProps): string | boolean => {
5052 } )
5153}
5254
53- const AddToCalendar = ( { eventDate, title, location } : AddToCalendarProps ) => {
55+ const AddToCalendar = ( {
56+ eventDate,
57+ startDateTime,
58+ endDateTime,
59+ title,
60+ location,
61+ } : AddToCalendarProps ) => {
5462 const intl = useTranslations ( )
5563 const [ fileData , setFileData ] = useState < string | boolean > ( false )
5664
5765 useEffect ( ( ) => {
5866 const { start : startString , end : endString } = getEventDates ( eventDate )
67+ if ( ! startString && ! eventDate ?. date && ! startDateTime ) return
5968
60- if ( ! startString ) return
61-
62- const start = new Date ( startString )
69+ const start = new Date ( startDateTime ?? startString ?? eventDate ?. date )
6370
6471 let end : Date
65- if ( ! endString ) {
72+ if ( ! endString || ! endDateTime ) {
6673 /* If time is not specified add to calendar as a full day */
67- end = new Date ( startString )
74+ end = new Date ( startDateTime ?? startString ?? eventDate ?. date )
6875 start . setHours ( 0 , 0 , 0 )
6976 end . setHours ( 23 , 59 , 59 )
7077 } else {
71- end = new Date ( endString )
78+ end = new Date ( endDateTime )
7279 }
7380
7481 if ( isUpcoming ( end ) ) {
@@ -82,7 +89,7 @@ const AddToCalendar = ({ eventDate, title, location }: AddToCalendarProps) => {
8289 }
8390 setFileData ( createICS ( eventData ) )
8491 }
85- } , [ eventDate , location , title ] )
92+ } , [ eventDate , startDateTime , endDateTime , location , title ] )
8693
8794 if ( ! fileData ) return null
8895 const atc = intl ( 'add_to_calendar_event' )
0 commit comments