Skip to content

Instantly share code, notes, and snippets.

@WrathChaos
Created February 27, 2021 11:09
Show Gist options
  • Save WrathChaos/f3f728821d40d52c5418393a6c37ba27 to your computer and use it in GitHub Desktop.
Save WrathChaos/f3f728821d40d52c5418393a6c37ba27 to your computer and use it in GitHub Desktop.
func greetingLogic() -> String {
  let hour = Calendar.current.component(.hour, from: Date())
  
  let NEW_DAY = 0
  let NOON = 12
  let SUNSET = 18
  let MIDNIGHT = 24
  
  var greetingText = "Hello" // Default greeting text
  switch hour {
  case NEW_DAY..<NOON:
      greetingText = "Good Morning"
  case NOON..<SUNSET:
      greetingText = "Good Afternoon"
  case SUNSET..<MIDNIGHT:
      greetingText = "Good Evening"
  default:
      _ = "Hello"
  }
  
  return greetingText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment