shoheiyokoyama / Koyomi

Simple customizable calendar component in Swift :calendar:
MIT License
749 stars 103 forks source link

How to show calendar month by Date() ? #36

Open loverde-co opened 6 years ago

loverde-co commented 6 years ago

If i want some date in specific month, how to show calendar koyomi on that month ?

springlo commented 6 years ago

update the DateModel.swift:

public enum MonthType {
    case previous
    case current
    case next
    case custom(year: Int, month: Int)
}

then

func display(in month: MonthType) {
        currentDates = []
        currentDate = date(of: month)
        setup()
    }
    func date(of month: MonthType) -> Date {
        var components = DateComponents()

            switch month {
                case .previous: components.month = -1
                case .current:  components.month = 0
                case .next:     components.month = 1
                case let .custom(year: year, month: month):
                    components.year = -year
                    components.month = -month
            }

        return calendar.date(byAdding: components, to: currentDate) ?? Date()
    }
mohseen-headyio commented 6 years ago

@springlo What about if it is used as a pod ? What do we need to do make this changes reflect ?