cache entries to help with header stutter

This commit is contained in:
Trey t
2022-03-08 23:13:36 -06:00
parent 63911ea90d
commit b2519dcd2d

View File

@@ -34,11 +34,17 @@ class Random {
return updateTime
}
static var existingWeekdayName = [Int: String]()
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]
if let value = Random.existingWeekdayName[dayIndex] {
return value
}
let newValue = calendar.weekdaySymbols[dayIndex]
Random.existingWeekdayName[dayIndex] = newValue
return newValue
}
static func monthName(fromMonthInt: Int) -> String {
@@ -46,13 +52,20 @@ class Random {
return monthName
}
static var existingDayFormat = [NSNumber: String]()
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)) ?? ""
let num = NSNumber(integerLiteral: day)
if let value = existingDayFormat[num] {
return value
}
let newValue = formatter.string(from: num) ?? ""
existingDayFormat[num] = newValue
return newValue
}
static func createTotalPerc(fromEntries entries: [MoodEntry]) -> [MoodMetrics] {