forked from Nutlope/roomGPT
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
65 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,24 @@ | ||
import { utcToZonedTime } from "date-fns-tz"; | ||
import { differenceInMilliseconds } from "date-fns"; | ||
|
||
export default function getRemainingTime() { | ||
const now = new Date(); | ||
|
||
// Convert current date and time to Eastern Timezone | ||
const et = utcToZonedTime(now, "America/New_York"); | ||
|
||
// Determine if current time is before or after 7pm ET | ||
const isBefore7pmET = et.getHours() < 19; // 7pm ET is 19:00 in 24-hour time | ||
|
||
// Calculate time difference between now and 7pm ET today or tomorrow | ||
const targetDate = new Date(et); | ||
targetDate.setHours(19, 0, 0, 0); | ||
if (!isBefore7pmET) { | ||
targetDate.setDate(targetDate.getDate() + 1); | ||
} | ||
const timeDiff = differenceInMilliseconds(targetDate, et); | ||
const hours = Math.floor(timeDiff / 1000 / 60 / 60); | ||
const minutes = Math.floor(timeDiff / 1000 / 60) - hours * 60; | ||
|
||
return { hours, minutes }; | ||
} |