-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
570b355
commit e66f21a
Showing
2 changed files
with
47 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use client'; | ||
//import react | ||
import React from 'react'; | ||
import { format } from 'date-fns'; | ||
|
||
//ensures startTime and endTime are Date types | ||
interface ClientEventTimeProps { | ||
startTime: Date; // start time of event in UTC | ||
endTime: Date; // end time of event in UTC | ||
} | ||
|
||
const ClientEventTime: React.FC<ClientEventTimeProps> = ({ | ||
startTime, | ||
endTime, | ||
}) => { | ||
//convert the startTime from UTC to the users local time with the Date object | ||
//tolocalestring gives the date and time formatted according to users local time | ||
const localStartTime = new Date(startTime).toLocaleString(undefined, { | ||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
//same | ||
const localEndTime = new Date(endTime).toLocaleString(undefined, { | ||
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
}); | ||
|
||
//resturn span element that dispalys local start and end time | ||
return ( | ||
<span> | ||
{localStartTime} - {localEndTime} | ||
</span> | ||
); | ||
}; | ||
//export it | ||
export default ClientEventTime; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters