Last active
March 13, 2018 10:45
-
-
Save jaderfeijo/8666ec1646461e33b899b545992f85aa to your computer and use it in GitHub Desktop.
Date+TimeOfDay.swift
This file contains hidden or 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
// | |
// Date+TimeOfDay.swift | |
// Created by: Jader Feijo | |
// | |
import Foundation | |
extension Date { | |
enum TimeOfDay { | |
case morning | |
case afternoon | |
case evening | |
var description: String { | |
switch self { | |
case .morning: | |
return "Morning" | |
case .afternoon: | |
return "Afternoon" | |
case .evening: | |
return "Evening" | |
} | |
} | |
} | |
var timeOfDay: TimeOfDay { | |
if hour >= 3 && hour < 12 { | |
return .morning | |
} else if hour >= 12 && hour < 18 { | |
return .afternoon | |
} else { | |
return .evening | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment