views:

114

answers:

3

I'd like to build a view that allows the user to get a list of things that are happening around a certain time.

What is the best way to build this request? E.g. If I wanted to get all of the events that are happening right now I could post to /events/2009/09/29/8/23/

That seems rather tedious especially if I want to have multiple dates in a request. I could end up with urls that look like /events/between/2009/09/29/8/23/2006/11/16/14/45/

Is there a simple (javascipt) way to convert a date/time to a timestamp and pass that in as an int, which I can then convert to a datetime inside the view?

A: 

You could do something like this:

var d = new Date("2009-09-30"); var timestamp = d.getTime()/1000.0;

This will get you a timestamp using JavaScript.

dijxtra
A: 
  • /events/2009/ -> all the events in 2009
  • /events/2009/09/ -> all the events in Aug-09
  • /events/2009/09/29/ -> all the events on 29-Aug-09
  • /events/2009/09/29/8/ -> all the events from 8:00 to 8:59 on 29-Aug-09
  • /events/2009/09/29/8/23/ -> all the events at 8:23 on 29-Aug-09
  • /events/2009/09/29/8/23/?10 -> all the events from 8:23 to 8:33 on 29-Aug-09
  • /events/2009/09/29/8/23/?91 -> all the events from 8:23 to 9:54 on 29-Aug-09
  • /events/2009/09/29/8/?10 -> all the events from 8:00 to 18:00 on 29-Aug-09
  • /events/2009/09/29/?10 -> all the events from 29-Aug-09 to 8-Sep-09
  • /events/2009/09/?2 -> all the events in August and September
  • /events/2009/?2 -> all the events in 2009 and 2010
John Mee
+1  A: 

I'd use a more readable URL structure like this:

/events/2009-09-29/0823/
/events/2009-09-29/0823/to/2009-10-10/2100/

Here's some basic Javascript showing to build this structure:

function pad(number) {
 return (number < 10 ? '0' : '') + number
}
function simpleDate(date) {
 return date.getUTCFullYear() + '-' + pad(date.getUTCMonth()) + '-' + pad(date.getUTCDay())
}
function simpleTime(date) {
 return pad(d.getUTCHours()) + pad(d.getUTCMinutes())
}
var d = new Date();
alert('/events/' + simpleDate(d) + '/' + simpleTime(d) + '/');
SmileyChris