Last active
September 6, 2018 17:24
-
-
Save sandeepsuvit/8c39de384cc8cb8838e4298803861f74 to your computer and use it in GitHub Desktop.
Utility to get time of day example Morning, Afternoon or Evening
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
// Set of utility functions | |
export const TimeUtils = { | |
/** | |
* Get the time of day | |
* ========================================================================= | |
* This utility will get the time of day like Morning, Afternoon, Evening. | |
* <br/> | |
* | |
* example: getTimeOfDay() -> morning | |
* example: getTimeOfDay(new Date()) -> afternoon | |
* <br/> | |
* | |
* @return {[type]} [description] | |
*/ | |
getTimeOfDay: function(now: Date = null): string { | |
const currHour = now ? now.getHours() : new Date().getHours(); | |
return currHour < 12 ? 'morning' : currHour < 18 ? 'afternoon' : 'evening'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment