-
Notifications
You must be signed in to change notification settings - Fork 150
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
Moment.js does not work for date queries #753
Comments
@jakeleventhal Sorry to hear about your trouble. For now, we only special-case JavaScript's Date (as well as our own Timestamp object). You can convert a |
Yeah, we currently do that. It just seems like an unnecessary step. Wouldn't the fix be as simple as adding the following to the where clause check? I was going to make the PR myself but i didn't want to waste my breath if you guys aren't okay with it. if (typeof val === 'object' && val.constructor.name === 'Moment') {
val = val.toDate();
} I understand not wanting to add special case checks for esoteric object types - it's just that moment is used in so many projects. |
I talked to some of the folks internally, and we are a little hesitant about adding first party support, especially given existing proposals to add better time management to the Node standard library (such as https://github.com/tc39/proposal-temporal). We can still keep this open as a feature request, which will allow us to gather more feedback. |
perhaps a good compromise would be to add some samples (time permitting) that demonstrate using firestore in conjunction with moment? I personally love moment, but agree that it's probably a bit too opinionated of a dependency to pull in directly. |
Just to clarify - we could accept it as an input type even without a dependency. I don't think we would ever return it from a DocumentSnapshot though (which might be a reason to also not accept it as input). |
Right @schmidt-sebastian, @bcoe the sample code i provided above is all that you would need. Just a check on the string type to see if the object is of type "Moment" |
Environment details
@google-cloud/firestore
version: 2.2.8Steps to reproduce
Moment.js is such a popular library used for dates that i think an exception should be made for this.
The text was updated successfully, but these errors were encountered: