如何根据星期隐藏FSCalendar的第二天

时间:2019-01-30 05:12:42

标签: swift calendar fscalendar

您好,如果用户注册日期和当前日期都相同,我想隐藏下一个工作日。我需要下一个工作日隐瞒。 周日和周六是假期。

如果用户在星期五注册,我会写下面的代码,我需要隐藏星期一,如何解决此问题。

我这样写如何隐藏工作日

func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {


        let joingdate = "2019-01-30" //modeldata.joindate
        let currentdate = date.toString(dateFormat: "yyyy-MM-dd")
        let currentDate = date
        let currentdayweek = date.toString(dateFormat: "EEEE")
        if joingdate == currentdate
        {
            if currentdayweek == "Friday"{
                let businessday = Calendar.current.date(byAdding: .day, value: 3, to: currentDate)
                return false
            }
            else if currentdayweek == "Saturday"{

                let businessday = Calendar.current.date(byAdding: .day, value: 2, to: currentDate)
                return false
            }
            else if  currentdayweek == "Sunday"{
                let businessday = Calendar.current.date(byAdding: .day, value: 1, to: currentDate)
                return false
            }
            else
            {
                let businessday = Calendar.current.date(byAdding: .day, value: 1, to: currentDate)
                return false
            }
        }
}

1 个答案:

答案 0 :(得分:0)

func minimumDate(for calendar: FSCalendar) -> Date {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let myString = formatter.string(from: Date())
        let yourDate = formatter.date(from: myString)
        formatter.dateFormat = "yyyy-MM-dd"
        let strCurrentDate = formatter.string(from: yourDate!)

        var addDay = 0
        if let model = modeldata{
            if let joiningdate = "2019-01-31"
            {
                if strCurrentDate == joiningdate
                {
                    addDay = 2
                }

                let currentdayweek = yourDate!.toString(dateFormat: "EEEE")

                if currentdayweek == "Friday"{
                    addDay = 4
                }
                else if currentdayweek == "Saturday"{

                    addDay = 3
                }
                else if  currentdayweek == "Sunday"{

                    addDay = 2
                }
            }
        }

        let tomorrow = Calendar.current.date(byAdding:
            .day, // updated this params to add hours
            value: addDay,
            to: formatter.date(from: strCurrentDate)!)

        return tomorrow!
    }  
}