Skip to content

Instantly share code, notes, and snippets.

@WrathChaos
Last active February 27, 2021 11:03
Show Gist options
  • Save WrathChaos/17c4c761faff355cdb8b6d8d3ae2f2a8 to your computer and use it in GitHub Desktop.
Save WrathChaos/17c4c761faff355cdb8b6d8d3ae2f2a8 to your computer and use it in GitHub Desktop.
func greetingLogic() -> String {
  let date = NSDate()
  let calendar = NSCalendar.current
  let currentHour = calendar.component(.hour, from: date as Date)
  let hourInt = Int(currentHour.description)!
  
  let NEW_DAY = 0
  let NOON = 12
  let SUNSET = 18
  let MIDNIGHT = 24

  var greetingText = "Hello" // Default greeting text
  if hourInt >= NEW_DAY && hourInt <= NOON {
      greetingText = "Good Morning"
  }
  else if hourInt > NOON && hourInt <= SUNSET {
      greetingText = "Good Afternoon"
  }
  else if hourInt > SUNSET && hourInt <= MIDNIGHT {
      greetingText = "Good Evening"
  }
  
  return greetingText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment