PlainTime.prototype.toString()
includes seconds by default. Possible to set smallestUnit: "minutes"
as a global default?
#260
-
In my application, I exclusively work with hours and minutes, never with seconds. My own web APIs take strings in Is it possible to set a global default? That would make it possible to write code like this: const appointment = {
start: Temporal.PlainTime.from("09:00"),
duration: "PT15M"
}
// 😀 short and sweet
await createAppointment(appointment)
// 🙁 sent to the api: { start: "09:00:00", duration: "PT15M" } Instead of like this: // 🙁 long and wordy
await createAppointment({ start: appointment.start.toString({ smallestUnit: "minutes" }), duration: appointment.duration })
// 😀 sent to the api: { start: "09:00", duration: "PT15M" } |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Thanks for the question! No, there is no global default. ECMAScript generally avoids global state, because one user's changes can affect other code. But here's a few possible ways you could customize things to get what you want:
Good luck with your project! |
Beta Was this translation helpful? Give feedback.
Thanks for the question! No, there is no global default. ECMAScript generally avoids global state, because one user's changes can affect other code.
But here's a few possible ways you could customize things to get what you want:
JSON.stringify
replacer function.Temporal.prototype.toJSON
, but there's danger there because if your code calls into other libraries that use Temporal, then your patching could break them.Good luck with your project!