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

When Phone is in 12-hours mode events become 24hours long #173

Open
graldij opened this issue Mar 10, 2021 · 11 comments
Open

When Phone is in 12-hours mode events become 24hours long #173

graldij opened this issue Mar 10, 2021 · 11 comments
Labels
bug Something isn't working investigation

Comments

@graldij
Copy link

graldij commented Mar 10, 2021

Hello,
In the process of testing my app using the KVKCalendar, I noticed that whenever the iPhone has the 12-hours layout (e.g. 15.15 is 3.15 pm), the length of the events displayed is wrong: instead of the actual length they becomr 24-hours long (see screenshot). I tried to set style.timeSystem = TimeHourSystem.twentyFour but nothing has changed.
Is this a bug? Or are there some other style-settings useful to solve the problem?

Thanks!
WhatsApp Image 2021-03-10 at 15 31 26

@graldij graldij added the bug Something isn't working label Mar 10, 2021
@kvyatkovskys
Copy link
Owner

🤔 try to set style.timeSystem = TimeHourSystem.twelve

@graldij
Copy link
Author

graldij commented Mar 11, 2021

🤔 try to set style.timeSystem = TimeHourSystem.twelve

Nothing changes: correctly displayed for 24-hours system and with that strange behaviour for the 12-hours system

@graldij
Copy link
Author

graldij commented Mar 11, 2021

    var i: Int=0
    for course in courses {

        let isoDateStart = course.startEvent
        let dateStartFormatter = ISO8601DateFormatter()

        let isoDateEnd = course.endEvent
        let dateEndFormatter = ISO8601DateFormatter()
        var event = Event(ID: "\(i)")

        event.start = dateStartFormatter.date(from: isoDateStart)!
        event.end = dateEndFormatter.date(from: isoDateEnd)!
        event.text = course.name

        events.append(event)

        i=i+1
    }

That's the way I am creating the events, fyi

@kvyatkovskys
Copy link
Owner

could you print event.start & event.end, pls? to check data 🤔

@graldij
Copy link
Author

graldij commented Mar 11, 2021

For the following code

var i: Int=0
for course in courses {

    let isoDateStart = course.startEvent
    let dateStartFormatter = ISO8601DateFormatter()

    let isoDateEnd = course.endEven
    let dateEndFormatter = ISO8601DateFormatter()
    var event = Event(ID: "\(i)")
            

    event.start = dateStartFormatter.date(from: isoDateStart)!
    event.end = dateEndFormatter.date(from: isoDateEnd)!
    event.text = course.name

    print(event.start)
    print(event.end)
            
    print(dateStartFormatter.date(from: isoDateStart)!)
    print(dateEndFormatter.date(from: isoDateEnd)!)
            
    events.append(event)

    i=i+1
}

I get these outputs for 12-hours system:

2021-03-05 11:30:00 AM +0000
2021-03-05 1:30:00 PM +0000
2021-03-05 11:30:00 AM +0000
2021-03-05 1:30:00 PM +0000

And these for the correct 24-hours system:

2021-03-05 11:30:00 +0000
2021-03-05 13:30:00 +0000
2021-03-05 11:30:00 +0000
2021-03-05 13:30:00 +0000

@kvyatkovskys
Copy link
Owner

I'll check this but I think the problem is related to ISO8601DateFormatter()

@graldij
Copy link
Author

graldij commented Mar 12, 2021

Okay, thanks! Please let me know if you find something!

@kvyatkovskys
Copy link
Owner

Could not reproduce, works fine for me 🤔

@graldij
Copy link
Author

graldij commented Mar 27, 2021

well, that's strange. Did you change the entire iPhone hour-system, right?

@fatenumber25
Copy link

I fixed it in TimelineView.swift as below and solved it.

Before

let timeLabelFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "HH:mm"
    return formatter
}()

After

let timeLabelFormatter: DateFormatter = {
    let formatter = DateFormatter()
    formatter.dateFormat = "HH:mm"
    formatter.calendar = Calendar(identifier: .gregorian)
    formatter.locale = Locale(identifier: "en_US_POSIX")
    return formatter
}()

@kvyatkovskys
Copy link
Owner

Could you create a PR with your fix, pls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation
Projects
Status: No status
Development

No branches or pull requests

3 participants