Skip to content
This repository has been archived by the owner on May 16, 2020. It is now read-only.

Date parameters in filter endpoints should support multiple formats? #59

Closed
qasim opened this issue Apr 24, 2016 · 3 comments
Closed

Date parameters in filter endpoints should support multiple formats? #59

qasim opened this issue Apr 24, 2016 · 3 comments

Comments

@qasim
Copy link
Member

qasim commented Apr 24, 2016

There are 4 ways to create dates in JS:

new Date() // This moment
new Date(value) // Milliseconds since January 1, 1970
new Date(dateString) // ISO-8601 formatted date or datetime
new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]])

Right now, endpoints that take date as part of the filter query support the 4th method. We should add support for the other 3 as well.

I think we'd need a method to differentiate each call in our query parser.

  • For milliseconds since January 1, 1970, we could take an integer like date:1461461852.
  • For dateString, we could see if the string has commas or not? Although the special case is if for the 4th method, they only enter a year like date:"2016", then that has no commas in it. Maybe we check if the length of the string is 4 or something.

Opinions?

@kashav
Copy link
Member

kashav commented Apr 24, 2016

Was originally considering doing this, but was running into a problem when splitting the query, since dateString contains colons (split with a limit seems to omit everything after the first occurrence, so .split(':', 1) doesn't work in this case).

We can use this (let me know if you have a better solution):

x = 'date:"2016-04-01T12:05:30-04:00"'
x = [x.slice(0, x.indexOf(':')), x.slice(x.indexOf(':') + 1)] // ['date', '"2016-04-01T12:05:30-04:00"']

I'm assuming we apply the first case when they provide an empty string, something like date:"".

@qasim
Copy link
Member Author

qasim commented Apr 24, 2016

That solution looks elegant to me! And I agree with the date:"".

@qasim
Copy link
Member Author

qasim commented Apr 24, 2016

Looks great!

@qasim qasim closed this as completed Apr 24, 2016
@kashav kashav mentioned this issue Apr 30, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants