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

Support Js.Date.t #24

Open
joseferben opened this issue Sep 4, 2019 · 12 comments
Open

Support Js.Date.t #24

joseferben opened this issue Sep 4, 2019 · 12 comments
Labels
good first issue Good for newcomers

Comments

@joseferben
Copy link

Hey @ryb73!

First of all thanks for this wonderful ppx, it helped to get rid of quite some boilerplate code.

What would be really helpful if ppx_decode shipped with Js.Date.t decoder, even though JSON has no support for dates. Something like https://mlms13.github.io/bs-decode/docs/decoding-simple-values does, some sort of best effort new Date call on the string that is supposed to be a date.

Thanks,
Josef

@mrmurphy
Copy link
Contributor

mrmurphy commented Sep 5, 2019

I agree, it'd be nice to have some default. I've implemented multiple versions of my own Decco codecs for date, since sometimes I have to work with dates as ISO strings, and other times I work with them as number timestamps. But it would be nice to have Date available for Greenfield projects, and have it work with ISO strings by default.

@ryb73
Copy link
Member

ryb73 commented Sep 6, 2019

Interesting. I'm not sure yet about supporting Js.Date.t by default, for the reasons @mrmurphy mentioned, but it would make sense at least to add codecs that can be used with [@decco.codec]

@ryb73 ryb73 added the good first issue Good for newcomers label Sep 6, 2019
@mrmurphy
Copy link
Contributor

mrmurphy commented Sep 6, 2019

@ryb73 I think that's a good solution!

@tsnobip
Copy link

tsnobip commented Oct 23, 2019

hi @ryb73 I'd like to make a PR to add the codecs for Js.Date.t (one for ISO date string and one for timestamp), are there instructions on how to contribute?
I've forked, cloned, yarn installed, yarn postinstalled, yarn build-ppx, but when I enter yarn build-lib or yarn watch I get these errors :

yarn run v1.17.3
$ bsb -clean-world -make-world
Cleaning... 6 files.
Cleaning... 0 files.
[5/5] Building src/jest.cmj
[1/9] Building src/Codecs.mlast
env: node\r: No such file or directory

  We've found a bug for you!
  /Users/paul/code/ppx_decco/src/Codecs.re
  
  There's been an error running a preprocessor before the compilation of a file.
  This was the command:
  
  /Users/paul/code/ppx_decco/./ppx/ppx_decco.sh '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppxe04fc7' '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppx37c7b2'
  
[2/9] Building src/Decco.mlast
env: node\r: No such file or directory

  We've found a bug for you!
  /Users/paul/code/ppx_decco/src/Decco.re
  
  There's been an error running a preprocessor before the compilation of a file.
  This was the command:
  
  /Users/paul/code/ppx_decco/./ppx/ppx_decco.sh '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppx04fd7e' '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppx1b42a9'
  
[3/9] Building __tests__/test.mlast
env: node\r: No such file or directory

  We've found a bug for you!
  /Users/paul/code/ppx_decco/__tests__/test.re
  
  There's been an error running a preprocessor before the compilation of a file.
  This was the command:
  
  /Users/paul/code/ppx_decco/./ppx/ppx_decco.sh '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppx58b130' '/var/folders/_9/dh8gfmg13hz95cnhsgw4x_8m0000gn/T/camlppx20671f'
  
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@tsnobip
Copy link

tsnobip commented Oct 23, 2019

great lib by the way :)

@ryb73
Copy link
Member

ryb73 commented Oct 24, 2019 via email

@tsnobip
Copy link

tsnobip commented Oct 24, 2019

Yes yarn build-ppx was successful unlike yarn build-lib. I'm using macOS Mojave.

@tsnobip
Copy link

tsnobip commented Oct 24, 2019

it's my first time building native, do I have to install opam, make a switch to 4.02 etc?

@ryb73
Copy link
Member

ryb73 commented Oct 24, 2019

No, opam shouldn't be needed as esy will handle the installation of ocaml. What if you try running something like this?

$ echo "let _ = 1" > test.ml                                                                                                                                         master 
$ ./ppx/_esy/default/build/default/.ppx/ppx_decco/ppx.exe test.ml

@tsnobip
Copy link

tsnobip commented Oct 24, 2019

when I do that it prints :

let _ = 1

@ryb73
Copy link
Member

ryb73 commented Oct 24, 2019 via email

@tsnobip
Copy link

tsnobip commented Oct 24, 2019

OK I found the issue, it was just an end of line issue in ./ppx/ppx_decco.sh, converting it to LF made it work. Might be worth another PR to make it cross-platform using a .gitattributes :)

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

Successfully merging a pull request may close this issue.

4 participants