jackc / jackc/tod

Compatibility issue with Rails 5, Chrome 86 and Time fields

Open
#75 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
447
Forks
56
PR merge metrics
No merged PRs in 30d

Description

Not necessarily an issue with Tod, but a small change to Tod would fix the problem.

Using Tod::TimeOfDay in a Rails 5 app, with Chrome and HTML time fields. There seems to be an odd bit of behaviour in Chrome, in that if an HTML time field has been modified by the user, the contents are returned as "08:30", whilst if the field remains unmodified from when the form was created, the same field comes back as "08:30:00.000", which Tod::TimeOfDay.parse doesn't understand, resulting in the field in the database record being set to nil.

It would appear that when you create a time field in Rails for an item held in a Tod::TimeOfDay with:

<%= f.time_field :my_tod_time %>

Then the format used in the HTML sent to the browser is "08:30:00.000", and if the user doesn't modify it then that's what Chrome sends back. Tod::TimeOfDay then doesn't understand it and you end up with a nil field. I've tried changing default formatting for both Time and Tod::TimeOfDay but neither has en effect. I've yet to identify what causes the long string to be generated in the first place.

I'm far from sure where the fundamental inconsistency is here. Feedback appreciated.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Rails form behavior described for f.time_field :my_tod_time and trace how the returned values reach Tod::TimeOfDay.parse. Compare handling of "08:30" and "08:30:00.000"; done means the unchanged HTML time-field value no longer becomes nil, with coverage for both formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.