-
-
Notifications
You must be signed in to change notification settings - Fork 457
Description
Steps to reproduce
-
Set up a table like this:
Verify all UI matches with the arrows.
-
Open your browser dev tools network tab.
-
Copy the string:
2000-01-01 09:00:00 -
Edit the
date_timecell. While in edit mode, paste the string and press Enter to save. -
In your dev tools, observe that Mathesar sends something like the following:
2000-01-01 09:00:00 -05:00That
-05:00bit at the end is the timezone, as determined by your browser. It might be different for you depending on what timezone you're in.This is good. The front end doesn't just tack this on at the end. The front end actually parses your entire date entry and then reformats it in a format that PostgreSQL can interpret unambiguously.
-
Add a new record and edit the
date_timecell, this time pasting the following value:2000-01-01 9:00:00Notice that the only thing we've change here is that we've removed the leading 0 before the 9.
-
This time, observe that Mathesar sends exactly the string you entered.
-
And (unless you're in UTC timezone) PostgreSQL will actually send back will be a different time, making the displayed cell different from you you entered. This is bad.
What's going on (and how to fix it!)
-
On the front end, find the
DateTimeFormatterclass, and look at theparsemethod. You can see some code comments describing how this logic works (and why). -
We need to make the
parseWithSpecfree function more robust so as to handle input like the format in the above repro steps. The bulk of your changes will probably end up being inDateTimeSpecification.ts. -
You can tighten your feedback loop on this parsing function by adding so console logging in
DateTimeFormatter.parseand observing the output as you type into the input on the record page:
-
It would be good to try to think of additional date/time formats that we can parse in addition to the one listed above.
Additional context
- This bug was originally described in Maddening behavior when entering data into "TIMESTAMP WITH TIME ZONE" column #4911