forked from RaffiKian/RKCalendar
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RKManager.swift
56 lines (45 loc) · 1.77 KB
/
RKManager.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// RKManager.swift
// RKCalendar
//
// Created by Raffi Kian on 7/14/19.
// Copyright © 2019 Raffi Kian. All rights reserved.
//
import SwiftUI
public class RKManager : ObservableObject {
@Published public var calendar = Calendar.current
@Published public var minimumDate: Date = Date()
@Published public var maximumDate: Date = Date()
@Published public var disabledDates: [Date] = [Date]()
@Published public var selectedDates: [Date] = [Date]()
@Published public var selectedDate: Date! = nil
@Published public var startDate: Date! = nil
@Published public var endDate: Date! = nil
@Published public var mode: Int = 0
public var colors = RKColorSettings()
public init(calendar: Calendar, minimumDate: Date, maximumDate: Date, selectedDates: [Date] = [Date](), mode: Int) {
self.calendar = calendar
self.minimumDate = minimumDate
self.maximumDate = maximumDate
self.selectedDates = selectedDates
self.mode = mode
}
public func selectedDatesContains(date: Date) -> Bool {
if let _ = self.selectedDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) {
return true
}
return false
}
public func selectedDatesFindIndex(date: Date) -> Int? {
return self.selectedDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) })
}
public func disabledDatesContains(date: Date) -> Bool {
if let _ = self.disabledDates.first(where: { calendar.isDate($0, inSameDayAs: date) }) {
return true
}
return false
}
public func disabledDatesFindIndex(date: Date) -> Int? {
return self.disabledDates.firstIndex(where: { calendar.isDate($0, inSameDayAs: date) })
}
}