tempo icon indicating copy to clipboard operation
tempo copied to clipboard

Optional argument in `is*` functions

Open Serator opened this issue 1 year ago • 3 comments

In case we are comparing with the current time, the second argument could be omitted.

image

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.

image

Most likely, in functions other than is* you can follow the same way and not write new Date() in case the operation is performed with the current time.

Serator avatar Apr 23 '24 08:04 Serator

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

WilcoSp avatar Apr 25 '24 19:04 WilcoSp

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.

Serator avatar Apr 25 '24 20:04 Serator

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

WilcoSp avatar Apr 25 '24 22:04 WilcoSp