I am trying to format NSDates in a form where it uses the relative format when applicable and the day of the week when not: "Today", "Tomorrow", "Sunday", "Monday", …
The problem is, NSDateFormatter’s doesRelativeFormatting only works when using dateStyle, and not with dateFormat. (Basically, I’d need the functionality of dateFormat = "EEEE" for all days after tomorrow.)
At the moment, I’m using the following code:
let dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = .NoStyle
dateFormatter.dateStyle = .FullStyle
dateFormatter.doesRelativeDateFormatting = true
let dateString = dateFormatter.stringFromDate(theDate)
return dateString.componentsSeparatedByString(" ")[0]
Which just happens to work in my specific locale where NSDateFormatterStyle.FullStyle outputs something like "Sunday 23 August 2015", but obviously that’s not a good or general solution.
The closest thing I found would be this question, but it seems unnecessarily complex for my use case, and I’d like something more elegant, if possible.
Thanks!