Open Serator opened 6 months ago
this comes from the date function which converts an undefined value to a new Date object with the current time.
for at least the is*
and diff*
functions it might be a nice idea to make some argument(s) optional to use the current time
This would also work well with add*
functions and such, but I don't see a way to do it without breaking the current design. Unless you use an explicit null
as a keyword (addDay(null, 5)
) or something like that, but it doesn't look like much. In any case, I would like a consistent solution.
If it would be implemented I do think it would be best to use typescript's function overload feature to provide more jsdoc, but also prevent unexpected behaviour from being created (like isAfter(null,null)
)
Also it's maybe best to first discuss together with Justin and other contributors which function categories and/or independent functions should allow for null/undefined arguments as this could have a big impact on Tempo
In case we are comparing with the current time, the second argument could be omitted.
It seems to work as expected, but it doesn't seem obvious from the docs.
It also causes a type error because the second argument is required.
Most likely, in functions other than
is*
you can follow the same way and not writenew Date()
in case the operation is performed with the current time.