Skip to content

Instantly share code, notes, and snippets.

@sandeepsuvit
Last active September 6, 2018 17:24
Show Gist options
  • Save sandeepsuvit/8c39de384cc8cb8838e4298803861f74 to your computer and use it in GitHub Desktop.
Save sandeepsuvit/8c39de384cc8cb8838e4298803861f74 to your computer and use it in GitHub Desktop.
Utility to get time of day example Morning, Afternoon or Evening
// 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