FSCalendar giving me one day back inside should select delegate method.

Created on 27 Oct 2017  路  5Comments  路  Source: WenchaoD/FSCalendar

Inside func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool
i am getting date of one day back , am i doing something wrong can you please help me .

Most helpful comment

i fixed this with category for Date:

extension Date {
    // Convert UTC (or GMT) to local time

    func toLocalTime() -> Date {

        let timezone = TimeZone.current

        let seconds = TimeInterval(timezone.secondsFromGMT(for: self))

        return Date(timeInterval: seconds, since: self)

    }

    // Convert local time to UTC (or GMT)

    func toGlobalTime() -> Date {

        let timezone = TimeZone.current

        let seconds = -TimeInterval(timezone.secondsFromGMT(for: self))

        return Date(timeInterval: seconds, since: self)

    }

}

and convert it in selectDate delegate:

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {

        print("did select date \(date)")

        let date = date.toLocalTime()

    }

All 5 comments

I am facing same issue.

We are getting same issue

i fixed this with category for Date:

extension Date {
    // Convert UTC (or GMT) to local time

    func toLocalTime() -> Date {

        let timezone = TimeZone.current

        let seconds = TimeInterval(timezone.secondsFromGMT(for: self))

        return Date(timeInterval: seconds, since: self)

    }

    // Convert local time to UTC (or GMT)

    func toGlobalTime() -> Date {

        let timezone = TimeZone.current

        let seconds = -TimeInterval(timezone.secondsFromGMT(for: self))

        return Date(timeInterval: seconds, since: self)

    }

}

and convert it in selectDate delegate:

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {

        print("did select date \(date)")

        let date = date.toLocalTime()

    }

This answer helped me thanks saved my time

Cool @vitalrum, I am closing the issue now as I am also getting the same day.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shilpashreemayigaiah picture shilpashreemayigaiah  路  3Comments

bizibizi picture bizibizi  路  3Comments

StanleySathler picture StanleySathler  路  5Comments

iHamzaaK picture iHamzaaK  路  5Comments

adavan2107 picture adavan2107  路  5Comments