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

Add support for moment >= 2.25 #1

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A [Waterline](https://github.com/waterlinejs) adapter for
## Compatibility
- [Waterline](http://waterline.js.org) v0.10 and newer
- [Trails](http://trailsjs.io) v1.0 and newer
- Node 4 or newer
- Node 12 or newer

## Install

Expand Down
5 changes: 4 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ const Util = {
}
if (_.isString(value)) {
let stripped = value.replace(/\"/g, '')
if (moment(stripped, moment.ISO_8601, true).isValid()) {
// Check the length of the stripped string. If it's longer than 4 characters, then convert it to a date using moment.
// This is to prevent an incompatibility with newer versions of moment that treat all 4 digit strings as years, which
// is technically in the ISO_8601 spec, but is not consistent with the way this library uses moment to parse dates.
if (stripped.length > 4 && moment(stripped, moment.ISO_8601, true).isValid()) {
return new Date(stripped).valueOf()
}
}
Expand Down