denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3.01k stars 603 forks source link

YAML: Allow to store dates without time #5680

Open oscarotero opened 1 month ago

oscarotero commented 1 month ago

Is your feature request related to a problem? Please describe.

I want to create a front matter with a code like this:

---
title: Post title
date: 2024-09-01
---

But YAML export the date value in this way:

---
title: Post title
date: 2024-09-01T19:00:00Z
---

The only way I found to save only the date (without time) was to convert the value to a string:

---
title: Post title
date: "2024-09-01"
---

But then this value is not parsed as Date.

Describe the solution you'd like

A way to store dates without including the time. As an idea, maybe detecting if the object is a Temporal.PlainDate instance.

kt3k commented 3 weeks ago

Maybe we can add support of replacer option in stringify like the same name option of JSON.stringify

iuioiua commented 3 weeks ago

Maybe we can add support of replacer option in stringify like the same name option of JSON.stringify

A replacer option is almost always a good idea, in my eyes. It allows users to cater to pretty much any of their use cases while keeping the API simple.