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

writer: dump date without time #569

Closed
Giszmo opened this issue Jul 22, 2020 · 6 comments
Closed

writer: dump date without time #569

Giszmo opened this issue Jul 22, 2020 · 6 comments

Comments

@Giszmo
Copy link

Giszmo commented Jul 22, 2020

A yaml property date: 2020-07-22 should survive the round trip but I get date: 2020-07-11T00:00:00.000Z.

@rlidwka
Copy link
Member

rlidwka commented Sep 15, 2020

A yaml property date: 2020-07-22 should survive the round trip

  • load(dump(xxx)) - any data should survive this round-trip
  • dump(load(xxx)) - but this round-trip is not guaranteed

the reason is: both date: 2020-07-22 and date: 2020-07-22T00:00:00.000Z are represented as the same date object - new Date(1595376000000) - in javascript, and it has no information left about original yaml formatting

and given the choice of how to dump a particular date, I think it's better to go with more explicit representation

@Giszmo
Copy link
Author

Giszmo commented Sep 15, 2020

While it's really annoying for my yaml use, I see your point.

A date-String ending in T00:00:00.000Z is arguably redundant, too though and could by the same logic be pruned to save 14 bytes per Date.

@rlidwka
Copy link
Member

rlidwka commented Sep 16, 2020

Can you fix it for your own app with a hack similar to this?: #570 (comment)

I wonder if there should just be a public api to customize dumper output.

@Giszmo
Copy link
Author

Giszmo commented Sep 16, 2020

I think if this is not of broader interest, the issue can be closed. If there was broader interest, I might make a PR to remove "trailing zeros" in Date dumps. Doesn't feel terribly complicated and would be in line with trailing zeros vanishing for floats, right? ;)

@rlidwka
Copy link
Member

rlidwka commented Sep 16, 2020

Doesn't feel terribly complicated and would be in line with trailing zeros vanishing for floats, right?

Floats are easy. If you write number 42 while being in europe, you don't usually expect some american computer to parse it as 42.3 (and switch to 42.4 during summer). 😕

T00:00:00.000 may be redundant, but Z is not. Need to carefully check yaml spec to see what happens if you miss it...

@Giszmo
Copy link
Author

Giszmo commented Sep 16, 2020

omg, locales are fun :D

You win

@Giszmo Giszmo closed this as completed Sep 16, 2020
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

2 participants