Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar Date Range background Between today date and selected end date #458

Closed
tharhtet opened this issue Oct 20, 2016 · 7 comments
Closed

Comments

@tharhtet
Copy link

Figure 1.
screen shot 2016-10-20 at 10 12 47 am

Figure 2.
screen-shot-2016-10-20-at-10 12 47-am-1

I would like to get design like Figure 2.

I would like to add the color between today date and selected end date.
But I don't know how to.
When I select the preferable end date, today date color will change to red color background.
And all the dates between today date and selected date will be changed into light blue.
For example if today date is (20.10.2016), I select the end date into (25.10.2016)
So all the dates between 20.10.2016 to 25.10.2016 background will be light blue.
And the minimum date will be today date.

May I know how can I do that.
And does this library support how I wanted to do?

Thanks a lot!

@WenchaoD
Copy link
Owner

@tharhtet You can use FSCalendarDelegateAppearance. See DelegateAppeanraceExample for details.

There is a gist to get all dates between two dates: https://gist.github.com/WenchaoD/4ee6276e36b2a5ccd02fddd367ebaae2

@tharhtet
Copy link
Author

tharhtet commented Oct 20, 2016

Is it correct to write within in didSelectDate? When i create within didSeletDate in DelegateAppeanraceExample, it doesn't work. May i know where will i write the selected date click event? Thank for the reply.

  • (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date;

@tharhtet
Copy link
Author

Although I get date lists between two dates, but the calendar Interface not change like Figure 2. May I know how to set the background between two dates? Thank.

@tharhtet
Copy link
Author

tharhtet commented Oct 31, 2016

I added the code below. The code is not working in swift. Although It added 2016/11/01 and 2016/11/02, it is adding ("2016-11-06 10:27:37 +0000", "2016-11-06 10:27:37 +0000"). Could i get solution. Thank a lot.

let fromDate = NSDate()
let toDate = fromDate.dateByAddingTimeInterval(3_24_3600)
let gregorian = NSCalendar(identifier: NSCalendarIdentifierGregorian)
let daysDiff = gregorian.components(NSCalendarUnit.Day, fromDate: fromDate, toDate: toDate, options: NSCalendarOptions(rawValue: 0)).day as Int
let array: NSMutableArray = []
for index in 1..<daysDiff {
let date = gregorian.dateByAddingUnit(NSCalendarUnit.Day, value: daysDiff, toDate: toDate, options: NSCalendarOptions(rawValue: 0))! as NSDate
array.addObject(date)
}
let dates = array.copy() as! NSArray
print(dates)

@tharhtet tharhtet reopened this Oct 31, 2016
@tharhtet
Copy link
Author

I have got the solution thank.

let calendar = NSCalendar.currentCalendar()
let normalizedStartDate = calendar.startOfDayForDate(fromDate)
let normalizedEndDate = calendar.startOfDayForDate(toDate)
var dates: NSMutableArray = []
var currentDate = normalizedStartDate
repeat {
currentDate = calendar.dateByAddingUnit(NSCalendarUnit.Day, value: 1, toDate: currentDate, options: NSCalendarOptions.MatchNextTime)!
dates.addObject(currentDate)
} while !calendar.isDate(currentDate, inSameDayAsDate: normalizedEndDate)
print(dates)

@elbertvaldian
Copy link

if you pick date from 20 until 25, how can i prevent if user pick on 22 and deselect the autoselect? it can be usefull for rangepicker.

thanks for helping

@xhidnoda
Copy link

xhidnoda commented Apr 26, 2018

If you date is today (20) you can disabled all date before 20 with shouldSelect Function.

func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
    
    let formatter = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd"
    
    if  formatter.string(from: TodayDate!) > formatter.string(from: date) {
       //date before 20
        return false
    }
   
    // dates after 20
    return true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants