iarna / iarna-toml

Better TOML parsing and stringifying all in that familiar JSON interface.
ISC License
316 stars 43 forks source link

Can i do a PR to represent dates with timezone offset? #35

Open randallb opened 4 years ago

randallb commented 4 years ago

Hi totally new to this project... love it btw!

Question: Are you interested in a PR to add timezone relative dates to the library?

ie

const thingy = {
date: new Date(),
};
TOML.stringify(thingy);

// date = 2020-07-03T22:21:32.426Z

I'd like to make it more human editable for my people using the product, so is it possible / plausible to change the stringified date into the user's local timezone?

date = 2020-07-03T21:21:32.426-01:00

Looks like I'd do this in stringify.js

How many bytes would you allow me to add? Should I do this in some sort of external way so you can turn it on and off? Should it be the default behavior?

iarna commented 4 years ago

That seems pretty reasonable to me. I'd prefer to avoid config options: Let's go with it as the new default.

One special note: If the date is currently UTC, then let's not change the current representation. Eg, continue to use the Z shortcut.

Uh, what do you mean by "how many bytes would you allow me to add"? =D

randallb commented 4 years ago

@iarna I work at FB... bytesize is a big deal to some ppl 😄 . I'll probably knock this out over the weekend.

randallb commented 4 years ago

https://github.com/iarna/iarna-toml/compare/latest...randallb:working#diff-c3fcfbed30e93682746088e2ce1a4a24R244-R257

I got it working, but tests aren't passing. I'll need to make the tests more resilient to this style of datestamp.

Will probably keep going, but might not. :) If someone really wants it, i'll do it, but i'm going to punt on this for my project right now.