code clean up

This commit is contained in:
Trey t
2022-02-10 23:30:19 -06:00
parent 014078c5fb
commit ad196b08c5
4 changed files with 213 additions and 174 deletions

View File

@@ -28,6 +28,27 @@ class Random {
}
return updateTime
}
static func weekdayName(fromDate date: Date) -> String {
let weekday = Calendar.current.component(.weekday, from: date)
let calendar = Calendar.current
let dayIndex = ((weekday - 1) + (calendar.firstWeekday - 1)) % 7
return calendar.weekdaySymbols[dayIndex]
}
static func monthName(fromMonthInt: Int) -> String {
let monthName = DateFormatter().monthSymbols[fromMonthInt-1]
return monthName
}
static func dayFormat(fromDate date: Date) -> String {
let components = Calendar.current.dateComponents([.day], from: date)
let day = components.day!
let formatter = NumberFormatter()
formatter.numberStyle = .ordinal
return formatter.string(from: NSNumber(integerLiteral: day)) ?? ""
}
}
extension Date: RawRepresentable {