0

i am trying to design a rest api which accepts a query parameter specifying a date range.
For a simple time range i do it like

&st=1407772800000&et=1408432033709

representing the start time and end time in epoch milliseconds.

But now i have a requirement wherein i need to specify a fractured (split) time range,

eg: all mondays and tuesdays within the given start and end time.

what would be the best way to represent this case as a query parameter?

Edit: i would only need to specify days of the week and timezone is UTC.
i am basically trying to specify blackout dates in a range

austin
  • 1,171
  • 1
  • 13
  • 32

4 Answers4

1

Your date range now needs to be split into multiple data ranges, since there are blackout dates in between.

For simplicity I will use date in the YYYYMMDD format in the example:

Assuming the following date range:

20140901 to 20140907

with a blackout date on 20140904

Then you will need to send two date ranges:

20140901 to 20140903
20140905 to 20140907

You can send the date ranges using a query parameter array, where each element contains a start date, end date pair:

&date-range=20140901-20140903&date-range=20140905-20140907

Check How to pass an array within a query string? for other query string array examples.

Community
  • 1
  • 1
Ricardo Veguilla
  • 3,107
  • 1
  • 18
  • 17
1

I would recommend that you just query multiple start and end dates, and if necessary, embed that into the query string protocol.

&st1=1407772800000&et1=1408432033709&st2=...&et2=...

The advantages are that you can easily error out if you have a malformed stX and etX pair, you can extend it to handle a start time without an end time (useful in half closed intervals), and you can add in as many ranges (overlapping or not) as you desire.

Other solutions are possible; however any kind of subtractive parameter passing (remove a time interval from the query) would require some semi-ugly interval math to subtract out properly, and if really done well, would require the same number of additional start and end times.

Solutions that include additional different time formats will just incur additional processing to work the different time format into a format consistent with the boundary formats, and might actually constrain future queries along date / day boundaries unnecessarily.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
0

I would suggest you to specify just blackout dates in addition to the information that is already sent. For example:

&st=1407772800000&et=1408432033709&bo=1407872800000%1407972800000%1408072800000

Note, that %2 is just a , character after URLEncode function. So, you will have list of blackout dates separated by comma. Inside your java code you can split them, sort by increasing time and make appropriate ranges:

1407772800000 - 1407872800000

1407872800000 - 1407972800000

1407972800000 - 1408072800000

1408072800000 - 1408432033709

Community
  • 1
  • 1
WhiteAngel
  • 2,594
  • 2
  • 21
  • 35
0

Inspired by Joda's Period I'd propose a pattern to specify the type of your query and append the details afterwards.

Something like

  • type=range&st= 1407772800000&et=1408432033709
  • type=period&st= 1407772800000&et=1408432033709&day=monday&day=tuesday
  • type=period&st= 1407772800000&et= 1408432033709&day=monday&day=tuesday&startHourOfDay=8&endHourOfDay=16

This approach allows to specify ranges (from/to) as well combined with periods within ranges

mp911de
  • 17,546
  • 2
  • 55
  • 95