You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a JavaScript object that contains a property which is a Date object. Currently, when I use the stringify function, it converts the Date object to this format:
Is there a way to customize the stringify function so that it converts Date properties into a local date without the time component?
It is the documented behavior for date objects indeed, to use other formats you'll need to use TomlDate. Note that you can treat it as a normal date object, it is perfectly compatible and will behave as expected (including with the type system)
I initially tried using TomlDate in my library, and it didn’t work as expected. However, after your comment, I tested it in a plain JavaScript project, and it functioned correctly, which indicates that the issue was within my library.
I understand that TomlDate is fully compatible when TOML is handled between machines. However, when users frequently interact with the TOML file and view the TOML string, it makes sense to simplify the date representation. Reducing unnecessary details in the date property can enhance clarity and make it easier for users to understand the TOML.
Thank you so much for your help. it's fixed now! I truly appreciate this library and you work for the community.
I understand that TomlDate is fully compatible when TOML is handled between machines. However, when users frequently interact with the TOML file and view the TOML string, it makes sense to simplify the date representation. Reducing unnecessary details in the date property can enhance clarity and make it easier for users to understand the TOML.
I'm unsure I understand that part; TomlDate extends the Date object so that it can be used transparently within your code, but preserves all the applicable semantics for what type of date it should serialize as. If a document is parsed and the document used a Local Date, the parser will emit a TomlDate that'll serialize back as a Local Date (and not a full datetime w/ tz). (more specifically, the toISOString method returns only the date).
I have a JavaScript object that contains a property which is a
Date
object. Currently, when I use thestringify
function, it converts theDate
object to this format:Is there a way to customize the
stringify
function so that it convertsDate
properties into a local date without the time component?https://toml.io/en/v1.0.0#local-date
The text was updated successfully, but these errors were encountered: