Last active
March 15, 2024 13:11
-
-
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
This file contains 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
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