You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
76 lines
2.0 KiB
//
|
|
// DateInterval.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 19/04/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
@Observable
|
|
final class DateInterval: BaseDateInterval {
|
|
|
|
// static func resourceName() -> String { return "date-intervals" }
|
|
// static func tokenExemptedMethods() -> [HTTPMethod] { return [] }
|
|
// static func filterByStoreIdentifier() -> Bool { return false }
|
|
// static var relationshipNames: [String] = []
|
|
//
|
|
// var id: String = Store.randomId()
|
|
// var lastUpdate: Date
|
|
// var event: String
|
|
// var courtIndex: Int
|
|
// var startDate: Date
|
|
// var endDate: Date
|
|
|
|
internal init(event: String, courtIndex: Int, startDate: Date, endDate: Date) {
|
|
super.init(event: event, courtIndex: courtIndex, startDate: startDate, endDate: endDate)
|
|
// self.lastUpdate = Date()
|
|
// self.event = event
|
|
// self.courtIndex = courtIndex
|
|
// self.startDate = startDate
|
|
// self.endDate = endDate
|
|
}
|
|
|
|
required init(from decoder: any Decoder) throws {
|
|
try super.init(from: decoder)
|
|
}
|
|
|
|
required public init() {
|
|
super.init()
|
|
}
|
|
|
|
var range: Range<Date> {
|
|
startDate..<endDate
|
|
}
|
|
|
|
func isSingleDay() -> Bool {
|
|
Calendar.current.isDate(startDate, inSameDayAs: endDate)
|
|
}
|
|
|
|
func isDateInside(_ date: Date) -> Bool {
|
|
date >= startDate && date <= endDate
|
|
}
|
|
|
|
func isDateOutside(_ date: Date) -> Bool {
|
|
date <= startDate && date <= endDate && date >= startDate && date >= endDate
|
|
}
|
|
|
|
override func deleteDependencies() {
|
|
}
|
|
|
|
// enum CodingKeys: String, CodingKey {
|
|
// case _id = "id"
|
|
// case _lastUpdate = "lastUpdate"
|
|
// case _event = "event"
|
|
// case _courtIndex = "courtIndex"
|
|
// case _startDate = "startDate"
|
|
// case _endDate = "endDate"
|
|
// }
|
|
|
|
func insertOnServer() throws {
|
|
DataStore.shared.dateIntervals.writeChangeAndInsertOnServer(instance: self)
|
|
}
|
|
|
|
}
|
|
|