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

DateFromUnixTime encode -> decode fails #159

Closed
saevarb opened this issue Mar 22, 2021 · 2 comments
Closed

DateFromUnixTime encode -> decode fails #159

saevarb opened this issue Mar 22, 2021 · 2 comments
Labels

Comments

@saevarb
Copy link
Contributor

saevarb commented Mar 22, 2021

🐛 Bug report

Current Behavior

DateFromUnixTime.encode returns a floating point number which its decoder refuses to accept.

Expected behavior

DateFromUnixTime.encode returns an integer so that decode(encode(x)) = x.

Reproducible example

const res = tt.DateFromUnixTime.encode(new Date());
console.log(res); // shows floating point number
console.log(tt.DateFromUnixTime.decode(res)); // returns Left

Your environment

   "fp-ts": "2.9.5",
    "io-ts": "2.2.16",
    "io-ts-types": "0.5.15",
    "monocle-ts": "2.3.9",
    "newtype-ts": "0.3.4",
    
@saevarb
Copy link
Contributor Author

saevarb commented Mar 22, 2021

I just realized I managed to post this in the wrong repository. This is particularly stupid of me because I realized I was about to do this half way through writing the issue, opened up the io-ts-types repository instead, copied the bug report over but somehow still finished it in this tab.

Should I close this and post this there or is there something a maintainer can do that is easier?

@gcanti gcanti transferred this issue from gcanti/io-ts Mar 23, 2021
@gcanti gcanti added the bug label Mar 23, 2021
@gcanti
Copy link
Owner

gcanti commented Mar 23, 2021

I think we should wrap the encoded value in Math.floor:

-a => a.getTime() / 1000
+a => Math.floor(a.getTime() / 1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants