Skip to content

Instantly share code, notes, and snippets.

@StewartLynch
Last active March 15, 2024 13:11

Revisions

  1. StewartLynch revised this gist Jan 22, 2024. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions DateString.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    static func capitalizedFirstLettersOfWeekdays() -> [String] {

    static var capitalizedFirstLettersOfWeekdays: [String] {
    let calendar = Calendar.current
    let weekdays = calendar.shortWeekdaySymbols

    @@ -8,7 +9,7 @@
    }
    }

    static func fullMonthNames() -> [String] {
    static var fullMonthNames: [String] {
    let dateFormatter = DateFormatter()
    dateFormatter.locale = Locale.current

  2. StewartLynch created this gist Jan 21, 2024.
    20 changes: 20 additions & 0 deletions DateString.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    static func 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 func 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) }
    }
    }