Created
July 3, 2024 07:49
-
-
Save velotiotech/fe653ba8b0984002c9eea89bd0ee444d to your computer and use it in GitHub Desktop.
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
struct MonthConfig { | |
let backgroundColor: Color // Background color for the month display | |
let dateText: String // Text describing specific dates or holidays in the month | |
let weekdayTextColor: Color // Text color for weekdays | |
let dayTextColor: Color // Text color for days of the month | |
let month: String // Name of the month | |
/// Determines and returns the configuration (MonthConfig) based on the given date. | |
/// | |
/// - Parameter date: The date used to determine the month configuration. | |
/// - Returns: A MonthConfig object corresponding to the month of the given date. | |
static func determineConfig(from date: Date) -> MonthConfig { | |
let monthInt = Calendar.current.component(.month, from: date) | |
switch monthInt { | |
case 1: // January | |
return MonthConfig(backgroundColor: .gray, | |
dateText: "1 and 26", | |
weekdayTextColor: .black.opacity(0.6), | |
dayTextColor: .white.opacity(0.8), | |
month: "Jan") | |
case 2: // February | |
return MonthConfig(backgroundColor: .palePink, | |
dateText: "No Holiday", | |
weekdayTextColor: .pink.opacity(0.5), | |
dayTextColor: .white.opacity(0.8), | |
month: "Feb") | |
case 3: // March | |
return MonthConfig(backgroundColor: .paleGreen, | |
dateText: "25", | |
weekdayTextColor: .black.opacity(0.7), | |
dayTextColor: .white.opacity(0.8), | |
month: "March") | |
case 4: // April | |
return MonthConfig(backgroundColor: .paleBlue, | |
dateText: "No Holiday", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .white.opacity(0.8), | |
month: "April") | |
case 5: // May | |
return MonthConfig(backgroundColor: .paleYellow, | |
dateText: "1", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .white.opacity(0.7), | |
month: "May") | |
case 6: // June | |
return MonthConfig(backgroundColor: .skyBlue, | |
dateText: "No Holiday", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .white.opacity(0.7), | |
month: "June") | |
case 7: // July | |
return MonthConfig(backgroundColor: .blue, | |
dateText: "No Holiday", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .white.opacity(0.8), | |
month: "July") | |
case 8: // August | |
return MonthConfig(backgroundColor: .paleOrange, | |
dateText: "15", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .white.opacity(0.8), | |
month: "August") | |
case 9: // September | |
return MonthConfig(backgroundColor: .paleRed, | |
dateText: "No Holiday", | |
weekdayTextColor: .black.opacity(0.5), | |
dayTextColor: .paleYellow.opacity(0.9), | |
month: "Sep") | |
case 10: // October | |
return MonthConfig(backgroundColor: .black, | |
dateText: "2", | |
weekdayTextColor: .white.opacity(0.6), | |
dayTextColor: .orange.opacity(0.8), | |
month: "Oct") | |
case 11: // November | |
return MonthConfig(backgroundColor: .paleBrown, | |
dateText: "31", | |
weekdayTextColor: .black.opacity(0.6), | |
dayTextColor: .white.opacity(0.6), | |
month: "Nov") | |
case 12: // December | |
return MonthConfig(backgroundColor: .paleRed, | |
dateText: "25", | |
weekdayTextColor: .white.opacity(0.6), | |
dayTextColor: .darkGreen.opacity(0.8), | |
month: "Dec") | |
default: | |
// Default case for unexpected month values (shouldn't typically happen) | |
return MonthConfig(backgroundColor: .gray, | |
dateText: "📅", | |
weekdayTextColor: .black.opacity(0.6), | |
dayTextColor: .white.opacity(0.8), | |
month: "None") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment