crate-admin
crate-admin copied to clipboard
Rendering of timestamps before 1970-01-01 (negative values in BIGINT) shows "Invalid Timestamp"
Issue:
The AdminUI automatically renders TIMESTAMP fields, which is very convenient.
Anyway, negative millisecond values are valid for dates that are before January 1970.
The following statement demonstrates the issue, the positive timestamp is rendered correctly, the negative one not:
-- Correct:
select ('1970-01-01T00:00:00.001000Z')::TIMESTAMP, date_format(1), (1)::TIMESTAMP limit 100;
-- Result
1 (1970-01-01T00:00:00.001Z) | 1970-01-01T00:00:00.001000Z | 1 (1970-01-01T00:00:00.001Z)
-- Incorrect:
select ('1969-12-31T23:59:59.999000Z')::TIMESTAMP, date_format(-1), (-1)::TIMESTAMP limit 100;
-- Result:
-1 (Invalid Timestamp) | 1969-12-31T23:59:59.999000Z | -1 (Invalid Timestamp)
Workaround: The issue is not really a problem, just confusing - I thought that my import is wrong, until I figured out this is only a rendering issue.
The date_format() function works properly.
I thought long about this auto-render timestamp, it's convenient until it's not and you actually need to see the raw values, perhaps adding some some info-icon next to the column name with a tooltip explaining that this is a value being rendered by the UI and not the raw value itself, and ideally some quick way to disabled this?
Highlighting that it is not the raw value might help (but for dates the value of bigint is shown).
I think we only need to change line 80 here: https://github.com/crate/crate-admin/blob/5abdc1485bbf4b725419dc012339e46fd1bf5ced/app/scripts/filter/text.js#L80
Instead of testing if .getTime() > 0, we should check if it is a valid date.