cobalt-uoft / cobalt

Open data APIs for interfacing with public information from the University of Toronto.
https://cobalt.qas.im
MIT License
98 stars 20 forks source link

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

Closed qasim closed 8 years ago

qasim commented 8 years ago

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.

Opinions?

kashav commented 8 years ago

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 commented 8 years ago

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

qasim commented 8 years ago

Looks great!