dimanche 6 septembre 2020

How to test local and UTC timezones in Android TimePicker?

I have an Android app whose main goal is to submit updates via a form on a website. The form takes the current time and date in UTC only and I suspect most users of my app will continue to expect the same. However, for some, it might benefit them to use local time so I have a preference to allow them to choose. The Time and Date is set by the user using the standard Android Time/Date pickers. I am looking for the best way to fully test their behavior.

If the user's preference is for UTC, I want to make sure the fragment loads with the proper UTC on layout inflation and not with the local time. Currently, this is broken as it's using the default Android behavior with always sets local time. I want to make sure I have a test to check this.

Also, if a user does have local time selected, I want to make sure the actual submission sends the correct UTC time. I currently have a mock to capture this, but I am not sure how to best handle the timezone conversion for the test.

In both cases, I want to make sure that it displays the correct UTC or local time matching the inflation time of the fragment and, when submitted, the time sent it s the current UTC in both cases. I feel like I'll probably need to create a test fixture for it that uses a known, fixed-offset time zone, and a set of known times, ideally one that crosses the current date so both pickers are tested. What is the best way to test this kind of setup?

Aucun commentaire:

Enregistrer un commentaire