Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date objects encoding is broken #4

Open
lbeschastny opened this issue Aug 24, 2022 · 0 comments
Open

Date objects encoding is broken #4

lbeschastny opened this issue Aug 24, 2022 · 0 comments

Comments

@lbeschastny
Copy link

lbeschastny commented Aug 24, 2022

Here is how Date objects are encoded right now:

if (v instanceof Date) return ('' + v.valueOf()).substr(0, 10)

This code has two problems.

First, it expects timestamp to have exactly 13 digits, which is wrong:

> ('' + new Date('2000-01-01').valueOf()).substr(0, 10)
'9466848000'
> ('' + new Date('2022-01-01').valueOf()).substr(0, 10)
'1640995200'

Second, it sends timestamps as strings which only works with DateTime type, but not with Date:

SELECT
    toDateTime(1661353838),
    toDate(1661353838),
    toDateTime('1661353838'),
    toDate('1661353838')
┌─toDateTime(1661353838)─┬─toDate(1661353838)─┬─toDateTime('1661353838')─┬─toDate('1661353838')─┐
│    2022-08-24 18:10:38 │         2022-08-24 │      2022-08-24 18:10:38 │           1970-01-01 │
└────────────────────────┴────────────────────┴──────────────────────────┴──────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant