未来日期未从Koyami日历正确显示

时间:2018-02-17 06:56:31

标签: ios swift calendar

enter image description here我的推荐是使用以下链接

https://github.com/shoheiyokoyama/Koyomi#demo_app

我想从日历中选择日期(startDate到endDate)。如果我使用Koyami日历从以下方法中选择日期。

 func koyomi(_ koyomi: Koyomi, didSelect date: Date?, forItemAt indexPath: IndexPath) {
    print("You Selected: \(date!)")
 }

如果我首先使用此功能,请选择开始日期示例(20.2.2018)并选择endDate示例(18.2.2018)。输出将正确显示。因为我从startDate中选择了上一个日期,我的控制台输出是

You Selected: 2018-02-20 18:30:00 +0000
You Selected: 2018-02-18 18:30:00 +0000

如果我首先使用相同的功能,我选择startDate示例(20.2.2018)和endDate示例(22.2.2018)。输出将正确显示。因为我从startDate选择未来日期我的控制台输出是

You Selected: 2018-02-20 18:30:00 +0000
You Selected: 2018-02-20 18:30:00 +0000

我的问题是当我选择endDate,startDate和endDate的未来日期时,将显示相同的日期。但我想正确地显示我的ecpectd输出是

You Selected: 2018-02-20 18:30:00 +0000
You Selected: 2018-02-22 18:30:00 +0000

我该如何解决这个问题。请帮助我!

1 个答案:

答案 0 :(得分:2)

你应该浏览koyomi的文档。默认情况下,它处于sequence模式,可供多选使用multiple模式。它将为您提供2个不同的选择日期。

    koyomi.selectionMode = .multiple(style: .background) //.sequence(style: .semicircleEdge)

更新:使用相同的选择模式= .sequence(style: .semicircleEdge)并从方法获取开始日期和结束日期: 在此开始日期将为date,结束日期为toDate

func koyomi(_ koyomi: Koyomi, shouldSelectDates date: Date?, to toDate: Date?, withPeriodLength length: Int) -> Bool {
    print("Start date \(date)")
    print("End date : \(toDate)")

    if length > invalidPeriodLength {
        print("More than \(invalidPeriodLength) days are invalid period.")
        return false
    }
    return true
}