Created
April 28, 2021 20:10
-
-
Save edbella/7f8be7ad4b4d5538ae2a51b958ab9d0f to your computer and use it in GitHub Desktop.
Revisions
-
edbella created this gist
Apr 28, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ /** * Assumes you are using dayjs * Buy ideally you can use any date formatting library or the native JavaScript Date Object Constructor */ /** * Gets the correct greeting time based now * * @returns {string} Greeting text */ export const getGreetingTime = () => { const dateNow = dayjs().format("HH"); // const dateNow = new Date().getHours(); - use this if you want to go the native route let g; const splitAfternoon = 12; // 24hr time to split the afternoon const splitEvening = 17; // 24hr time to split the evening const currentHour = parseFloat(dateNow); if (currentHour >= splitAfternoon && currentHour <= splitEvening) { g = "Good Afternoon"; } else if (currentHour >= splitEvening) { g = "Good Evening"; } else { g = "Good Morning"; } return g; };