Skip to content

Instantly share code, notes, and snippets.

@anandaanv
Created November 20, 2019 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandaanv/99689fd609e1342fe1022ed5bc270697 to your computer and use it in GitHub Desktop.
Save anandaanv/99689fd609e1342fe1022ed5bc270697 to your computer and use it in GitHub Desktop.
non-testable method, because of uncertainity
public String getTimeOfDay() {
Date time = new Date(); //new Date() will return current time. So the value of it will change in every hour.
if (time.getHours() >= 0 && time.getHours() < 6) {
return "Night";
}
if (time.getHours() >= 6 && time.getHours() < 12) {
return "Morning";
}
if (time.getHours() >= 12 && time.getHours() < 18) {
return "Afternoon";
}
return "Evening";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment