Expected behaviour
The is a super user friendly way to format dates into strings. We need one extension for each Date format (or one with 2 parameters, date and format):
extension String.StringInterpolation {
mutating func appendInterpolation(date: Date, format: SHDateFormat) {
let string = SHDateFormatter.shared.string(from: date, format: format)
appendLiteral(string)
}
}
// "Your time is \(date: Date(), format: .shortTimeNoDate)" <-- automatically compatible to new formats
OR
extension String.StringInterpolation {
mutating func appendInterpolation(shortTimeNoDate date: Date) {
let string = SHDateFormatter.shared.string(from: date, format: .shortTimeNoDate)
appendLiteral(string)
}
}
// "Your time is \(shortTimeNoDate: Date())" <-- a bit shorter but needs a new extension for each new format
[...]
Actual behaviour
Right now, to formt a string, a user has to use:
let time = SHDateFormatter.shared.string(from: Date(), format: .shortTimeNoDate)
let string = "Now is \(time)"
Expected behaviour
The is a super user friendly way to format dates into strings. We need one extension for each Date format (or one with 2 parameters,
dateandformat):Actual behaviour
Right now, to formt a string, a user has to use: