Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Last active March 15, 2024 13:11
Show Gist options
  • Save StewartLynch/90ecac7eff9fe438bba580e96643fe70 to your computer and use it in GitHub Desktop.
Save StewartLynch/90ecac7eff9fe438bba580e96643fe70 to your computer and use it in GitHub Desktop.
Two Static functions for getting weekday and month names for the Custom Calendar App
static var capitalizedFirstLettersOfWeekdays: [String] {
let calendar = Calendar.current
let weekdays = calendar.shortWeekdaySymbols
return weekdays.map { weekday in
guard let firstLetter = weekday.first else { return "" }
return String(firstLetter).capitalized
}
}
static var fullMonthNames: [String] {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
return (1...12).compactMap { month in
dateFormatter.setLocalizedDateFormatFromTemplate("MMMM")
let date = Calendar.current.date(from: DateComponents(year: 2000, month: month, day: 1))
return date.map { dateFormatter.string(from: $0) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment