xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.78k stars 1.33k forks source link

DateInlineRow / DateTimeInlineRow Timezone Bug #2106

Open kyleturner opened 4 years ago

kyleturner commented 4 years ago

We are experiencing a new issue with the inline DateInlineRow and DateTimeInlineRow specifically inconsistency on the timezone used for row value vs. picker input.

Environment

Issue

Our users can set a user profile timezone on their profile, allowing their timezone to be set to something other than their current locale/timezone from the iOS device.

We previously were using DateRow and DateTimeRow and correctly set the timezone using:

.onCellSelection{ (cell, _) in
    cell.datePicker.timeZone = metaData.timezone // Our custom TZ
}

Now, we removed the above code and have tried to hardcode the timezone directly using defaultCellSetup for the inline row experience (we exhausted all other options of configuring datePicker, but below is the simplest example):

DateTimeInlineRow.InlineRow.defaultCellSetup = { cell, row in
    cell.datePicker.timeZone = TimeZone(identifier: "Pacific/Auckland")
}

CORRECT: The display value and changing selected calendar date results in the correct value as seen in Date and Time 1 field below...

Screen Shot 2020-10-26 at 2 42 05 PM

INCORRECT: Calendar picker shows incorrect month when expanded - "October 2020" is displayed, but when expanded, it is showing "September 2020".

Screen Shot 2020-10-26 at 2 42 07 PM

Has anyone else experienced this or know how to resolve this?

UPDATE

Tried this in a Playground decoupled from Eureka completely... did I stumble upon a new date picker bug?

//: A UIKit based Playground for presenting user interface

import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    let picker = UIDatePicker()

    override func loadView() {
        let view = UIView()
        view.backgroundColor = .white

        picker.preferredDatePickerStyle = .inline
        picker.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
        picker.timeZone = TimeZone(identifier: "Pacific/Auckland")
        picker.calendar = Calendar(identifier: .gregorian)
        picker.date = Date()
        picker.addTarget(self,
                         action:#selector(MyViewController.datePickerValueChanged(_:)), for: .valueChanged)
        view.addSubview(picker)

        self.view = view
    }

    @objc func datePickerValueChanged(_ sender: UIDatePicker) {
        print("value: \(picker.date)")
    }
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()

If you don’t set the TZ, it works as expected, shows the correct month selected on expand, changes month as you scroll wheel.

If you set the TZ to "America/Denver" — it works. Heck, if you set it to "BOO" — it works (defaulting back to current, I believe).

However, if you set the TZ to "Pacific/Auckland" (your test case with NZ timezone) it borks — expanding months show September, and doesn’t change the month when you switch from October to September (stays October).

mats-claassen commented 4 years ago

If I understand you correctly this is a UIDatePicker bug? Have you filed a bug report to Apple?