denoland / std

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

YAML: Allow to store dates without time #5680

Open oscarotero opened 2 months ago

oscarotero commented 2 months 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 2 months ago

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

iuioiua commented 2 months 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.