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

Compare method should handle null | undefined PlainDate #3084

Open
mukesh-msci opened this issue Feb 7, 2025 · 1 comment
Open

Compare method should handle null | undefined PlainDate #3084

mukesh-msci opened this issue Feb 7, 2025 · 1 comment
Labels

Comments

@mukesh-msci
Copy link

I am using Temporal.PlainDate in column of Grid in my project, which may have null or undefined values. I am using Temporal.PlainDate.compare method as comparator for sorting rows which is failing while comparing with null and undefined values.

@ptomato
Copy link
Collaborator

ptomato commented Feb 12, 2025

Thanks for the feedback! This is not something that we're able to change at this point, but you could propose it for a future iteration at https://github.com/js-temporal/proposal-temporal-v2.

That said, I would personally suggest a different way than making compare() handle null out of the box, because undoubtedly some applications will need the nulls sorted first, some will need the nulls sorted last, some will need to handle null but not undefined, etc. So it seems kind of arbitrary if we were to choose one or the other for all JavaScript developers.

Here's an example snippet that you could use to sort nulls first:

list.sort((a, b) => {
  if (a === null) return -1;
  if (b === null) return 1;
  return Temporal.PlainDate.compare(a, b);
});

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

No branches or pull requests

2 participants