//
//  Calendar+Extensions.swift
//  PadelClub
//
//  Created by Razmig Sarkissian on 28/03/2024.
//

import Foundation

extension Calendar {
    func numberOfDaysBetween(_ from: Date?, and to: Date?) -> Int {
        guard let from, let to else { return 0 }
        let fromDate = startOfDay(for: from)
        let toDate = startOfDay(for: to)
        let numberOfDays = dateComponents([.day], from: fromDate, to: toDate)
        
        return numberOfDays.day! // <1>
    }
    
    func isSameDay(date1: Date?, date2: Date?) -> Bool {
        guard let date1, let date2 else { return false }
        
        return numberOfDaysBetween(date1, and: date2) == 0
    }

}
