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

Weird bug with two months #63

Closed
krisanthony opened this issue Jul 6, 2016 · 5 comments
Closed

Weird bug with two months #63

krisanthony opened this issue Jul 6, 2016 · 5 comments

Comments

@krisanthony
Copy link

Running into a weird bug I cannot seem to figure out. When there are two months to display, the second month displays fine, but scrolling to the left displays nothing (blank). However if I set the calendar to have more than two months everything displays fine..

@patchthecode
Copy link
Owner

patchthecode commented Jul 6, 2016

Are you using version 4.1.0 ? If not please do. Fixed a bug in it.

@patchthecode
Copy link
Owner

Omg. i see it. looking into it.

@patchthecode
Copy link
Owner

Ok its a small error on my part.

can you fix the following file in your code? look for JTAppleCalendarLayout.swift file. (select yes when it asks you to unlock it)
replace this function:

    func binarySearch<T: Comparable>(a: [T], key: T) -> Int {
        var range = 0..<a.count
        var midIndex: Int = 0
        while range.startIndex < range.endIndex {
            midIndex = range.startIndex + (range.endIndex - range.startIndex) / 2
            if midIndex + 1  >= a.count || key >= a[midIndex] && key < a[midIndex + 1] ||  a[midIndex] == key {
                return midIndex
            } else if a[midIndex] < key {
                range.startIndex = midIndex + 1
            } else {
                range.endIndex = midIndex
            }
        }
        return midIndex
    }

with this one

    func binarySearch<T: Comparable>(a: [T], key: T) -> Int {
        var range = 0..<a.count
        var midIndex: Int = 0
        while range.startIndex < range.endIndex {
            midIndex = range.startIndex + (range.endIndex - range.startIndex) / 2
            if midIndex + 1  >= a.count || key >= a[midIndex] && key < a[midIndex + 1] ||  a[midIndex] == key {
                break
            } else if a[midIndex] < key {
                range.startIndex = midIndex + 1
            } else {
                range.endIndex = midIndex
            }
        }
        if a.count < 3 { midIndex = 0}
        return midIndex
    }

This is just a dirty fix. I will fix the binary function in the morning. Then do an official release on saturday.

@patchthecode patchthecode self-assigned this Jul 6, 2016
patchthecode added a commit that referenced this issue Jul 6, 2016
Fixed Bug. When there are only 2 months, the binary search stops at index 1 before it can check item 0.

#63
@patchthecode
Copy link
Owner

patchthecode commented Jul 6, 2016

Fixed issue on master Branch. Release coming this weekend.

@krisanthony
Copy link
Author

Thanks for this, works great.

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

No branches or pull requests

2 participants