Created
March 1, 2018 05:27
-
-
Save eshwarenm/a3958afd60072b815353a80306bf46c6 to your computer and use it in GitHub Desktop.
MomentJS Malay Proper Greetings Pagi Tengah Hari Petang Malam Tengah Malam
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
function getGreetingTime (m) { | |
var g = null; //return g | |
if(!m || !m.isValid()) { return; } //if we can't find a valid or filled moment, we return. | |
var split_afternoon = 12; //24hr time to split the afternoon | |
var split_evening = 13; //24hr time to split the evening | |
var split_night = 20; | |
var split_midnight = 0; | |
var currentHour = parseFloat(m.format("HH")); | |
if(currentHour == 0){ | |
g = "tengah malam"; | |
} | |
else if(currentHour >= split_afternoon && currentHour < split_evening) { | |
g = "tengah hari"; | |
} else if(currentHour >= split_evening && currentHour < split_night) { | |
g = "petang"; | |
} else if(currentHour >= split_night){ | |
g = "malam"; | |
} | |
else { | |
g = "pagi"; | |
} | |
return g; | |
} | |
//USE : console.log(getGreetingTime(moment(thedate))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment