This commit is contained in:
Vladimir Dubovik
2024-12-11 13:33:35 +03:00
parent 57e241292f
commit 1de531abc8
13 changed files with 325 additions and 132 deletions

View File

@ -75,6 +75,24 @@ extension Date {
return month
}
func createNextMonth() -> [MonthWeek] {
let calendar = Calendar.current
let startOfLastDate = calendar.startOfDay(for: self)
guard let nextDate = calendar.date(byAdding: .day, value: 1, to: startOfLastDate) else {
return []
}
return fetchMonth(nextDate)
}
func createPreviousMonth() -> [MonthWeek] {
let calendar = Calendar.current
let startOfFirstDate = calendar.startOfDay(for: self)
guard let previousDate = calendar.date(byAdding: .month, value: -1, to: startOfFirstDate) else {
return []
}
return fetchMonth(previousDate)
}
func createNextWeek() -> [WeekDay] {
let calendar = Calendar.current
let startOfLastDate = calendar.startOfDay(for: self)

View File

@ -24,4 +24,50 @@ extension View {
return currentMonth == dateMonth && currentYear == dateYear
}
func isSameWeek(_ date1: Date, _ date2: Date) -> Bool {
return Calendar.current.compare(date1, to: date2, toGranularity: .weekOfYear) == .orderedSame
}
func weeksBetween(startDate: Date, endDate: Date) -> Int {
let calendar = Calendar.current
let startOfFirstDate = calendar.startOfDay(for: startDate)
let startOfEndDate = calendar.startOfDay(for: endDate)
let weekForDate1 = calendar.dateInterval(of: .weekOfMonth, for: startOfFirstDate)
let weekForDate2 = calendar.dateInterval(of: .weekOfMonth, for: startOfEndDate)
guard let startOfWeek1 = weekForDate1?.start else {
return 0
}
guard let startOfWeek2 = weekForDate2?.start else {
return 0
}
let components = calendar.dateComponents([.day], from: startOfWeek1, to: startOfWeek2)
let daysDifference = components.day ?? 0
return Int(ceil(Double(abs(daysDifference)) / 7.0))
}
func convertTimeString(_ input: String) -> [String] {
let parts = input.split(separator: "-")
if let firstPart = parts.first, let lastPart = parts.last {
return [String(firstPart), String(lastPart)]
} else {
return []
}
}
func getColorForClass(_ str: String) -> Color {
if (str.contains("LMS")) {
return Color("blueForOnline")
}
else if (str.contains("ВПК")) {
return Color("turquoise")
}
else {
return Color("greenForOffline")
}
}
}