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

dayjs.max(dayjs('2018-01-01')) ===null? #2306

Open
171h opened this issue May 11, 2023 · 1 comment
Open

dayjs.max(dayjs('2018-01-01')) ===null? #2306

171h opened this issue May 11, 2023 · 1 comment

Comments

@171h
Copy link

171h commented May 11, 2023

I think dayjs.max(dayjs('2018-01-01')) shoulde tobe dayjs('2018-01-01') instead of null

Snipaste_2023-05-11_18-34-10

@171h
Copy link
Author

171h commented May 11, 2023

in my case, i get many datestr containing null values,i just want the min/max one, but when only one isValid, i always get null.

// lss is an array having many datestr containing null values
const essDayjs = lss.map(i => dayjs(i)).filter(i => i.isValid())
const lsMin = dayjs.min(...essDayjs)
if (lsMin && lsMin.isValid())
  return lsMin.format('YYYY-MM-DD HH:mm:ss')
return null

I have to write bellow to get the results i want

const essDayjs = lss.map(i => dayjs(i)).filter(i => i.isValid())
if (essDayjs.length === 0)
  return null
if (essDayjs.length === 1)
  return essDayjs[0].format('YYYY-MM-DD HH:mm:ss')
const lsMin = dayjs.min(...essDayjs)
if (lsMin && lsMin.isValid())
  return lsMin.format('YYYY-MM-DD HH:mm:ss')
return null

@dchueri dchueri mentioned this issue Jun 9, 2023
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

1 participant