@@ -130,7 +130,51 @@ public enum WeekDay: String, Codable {
}
}
publicenumDayTime:Int,CaseIterable{
casemorning=7
casenoon=12
caseevening=18
casenight=23
publicvarlocalized:String{
switchself{
case.morning:
return"dayTime.morning".localized()
case.noon:
return"dayTime.noon".localized()
case.evening:
return"dayTime.evening".localized()
case.night:
return"dayTime.night".localized()
}
}
/// For a given date (with arbitrary time) in a given time zone returns a date object for canonical time for the given DayTime.
/// Example 1: Given a date 2020-01-01 04:33 UTC, dayTime .noon and timezone UTC+0, it will return 2020-01-01 12-00 UTC.
/// Example 2 (with a non-UTC time zone): given a date 2020-01-01 04:33 UTC, dayTime .noon and timezone UTC-5 it will return 2019-12-31 12 UTC,
/// because in UTC-5 it's still 2019-12-31, so it will return the canonical time for noon within that day.
///
/// The canonical times are:
/// • `.morning`: 7,
/// • `.noon`: 12,
/// • `.evening`: 18,
/// • `.night`: 23
///
/// - Parameters:
/// - dayTime: `DayTime`, for which we need to get the canonical time.
/// - day: A date for which we need to get a canonical time. The time part may be arbitrary as long as it's within the given date (according to the timeZone parameter).
/// - timeZone: TimeZone to use for time calculations.
/// - Returns: A date that corresponds to a canonical time within the day specified by the `day` parameter in a given timeZone