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

Sequelize v6.12.0+ is throwing an Error when using a moment.js object in date fields #13816

Closed
2 tasks done
cmelendez opened this issue Dec 23, 2021 · 9 comments · Fixed by #13818
Closed
2 tasks done

Comments

@cmelendez
Copy link

Bug Description

Sequelize is throwing an Invalid value error when using a moment.js object in DATETIME fields to do date comparisons. Additionally, when using a Moment object to set a date, the date value is set to 0000-00-00 00:00:00

This is happening since v6.12.0.

  User.findAll({
    where: {
      birthday: {
       [Op.gte]: moment()
      }
   }
  });

What do you expect to happen?

Moment objects should be accepted for date comparison, creation, etc. as usual.

What is actually happening?

An Invalid value error is thrown, crashing the app.

Invalid value Moment<2021-12-21T19:52:23+00:00>

Additional context

Environment

  • Sequelize version: 6.12.0
  • Node.js version: 16.13.0

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.

Would you be willing to resolve this issue by submitting a Pull Request?

  • No, I don't have the time, although I believe I could do it if I had the time...
@fzn0x
Copy link
Member

fzn0x commented Dec 23, 2021

Hello, just adjusted and created the fix in #13818, thanks for the issue.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 7.0.0-alpha.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sdepold
Copy link
Member

sdepold commented Dec 27, 2021

Could you please give it a try and see if it a try for you?

@sdepold
Copy link
Member

sdepold commented Dec 28, 2021 via email

@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2022

🎉 This issue has been resolved in version 7.0.0-alpha2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cmelendez
Copy link
Author

A bit late but just confirming that the fix is working properly. We are using v6.13.0.

Thanks a lot!

@yogithesymbian
Copy link

now 2022 .

sevenDaysAgoNew7 days ago:  Moment<2022-10-16T17:58:12+08:00>
Error: Invalid value Moment<2022-10-16T00:00:00+08:00>

@yogithesymbian
Copy link

yogithesymbian commented Oct 21, 2022

"sequelize": "^6.6.5",
    "sequelize-cli": "^6.2.0",
"moment": "^2.29.1",
    "moment-timezone": "^0.5.33",

here is my code

console.log('7 days ago: ', sevenDaysAgo) // would print Moment<2022-10-16T00:00:00+08:00>

          clock_in_time: { // unique situation when using created_at field , its work like a charm , but the other field datetime its not work
            [Op.gte]: sevenDaysAgo // doesnt work
            // [Op.gte]: '2022-10-16T00:00:00+08:00' // work
          }

@yogithesymbian
Copy link

ah solved here https://stackoverflow.com/a/46390179/8122500 toDate()

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

Successfully merging a pull request may close this issue.

4 participants