Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional argument in is* functions #56

Open
Serator opened this issue Apr 23, 2024 · 3 comments
Open

Optional argument in is* functions #56

Serator opened this issue Apr 23, 2024 · 3 comments

Comments

@Serator
Copy link

Serator commented Apr 23, 2024

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.

@WilcoSp
Copy link
Contributor

WilcoSp commented Apr 25, 2024

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

@Serator
Copy link
Author

Serator commented Apr 25, 2024

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.

@WilcoSp
Copy link
Contributor

WilcoSp commented Apr 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants