farmOS / field-kit

A modular, offline-first companion app to farmOS.
https://farmOS.org
GNU General Public License v3.0
62 stars 39 forks source link

Validation issue on logs from server with hour = 0 #348

Closed mstenta closed 4 years ago

mstenta commented 4 years ago

The logic that loads timestamps into the hour/minutes field in the Edit Log screen seems to need a tweak for properly parsing "midnight" timestamps.

In farmOS server, there are some quick forms/actions that create a midnight timestamp on logs (hour and minute are zero). When this gets loaded into Field Kit, it puts 0 in the Hour field, but highlights in in red and says that it can't be less than zero.

Screenshot_20200515-132911

To replicate: make a log on the server, set hour and minute to zero, sync to Field Kit, and open in the Edit Log screen.

mstenta commented 4 years ago

Hmm seems like I can't type 12 in when it's set to AM either. So it might not be possible to represent midnight at all?

jgaehring commented 4 years ago

I haven't tested this yet, but I'll note that we're using a 12-hr clock, not a 24-hr clock, so 0:00 AM is intentionally prohibited, since it's not a valid representation of time under that standard. It should be represented by 12:00 AM if you enter a midnight timestamp into farmOS and send it to FK. I'll investigate what's going on with the logic to prevent 12:00 AM from being used. I suspect it's got something to do with the AM/PM logic in the dateAndTimeToUnix function,

https://github.com/farmOS/farmOS-client/blob/425bae074da511268dd6684e4839d1b3ca2306f7/src/components/DateAndTimeForm.vue#L104-L111

or in the way the hour is set in the created() hook,

https://github.com/farmOS/farmOS-client/blob/425bae074da511268dd6684e4839d1b3ca2306f7/src/components/DateAndTimeForm.vue#L85-L87

which is duplicated in the watcher.

jgaehring commented 4 years ago

Did a little testing, just with a log I created in FK on my phone (v0.4.18), and there are some major problems changing the hour. I think we need to prohibit direct keyboard entry, or have a more explicit means of testing the validity of an input value and postpone emitting the timestamp until we get a valid input value (or onblur).