0

We want to use it for opening hours like...

  • Mo 11:00-13:00
  • Tue 9:00-18:00
  • Update Now required: Wed 8:00-11:30, Wed 12:00-17:00

We have a Ruby based server and deliver JSON and XML to the clients. We follow the ActiveResource pattern, so that we can use plug ins in our clients

That's our current proprietary approach:

"availabilities":[{"end_time":"00:00","weekdays":"0,1,2,3,4,5,6","start_time":"00:00"}]
Community
  • 1
  • 1
OneWorld
  • 17,512
  • 21
  • 86
  • 136

2 Answers2

2

cron format was designed specifically for this, including relative dates like "from midnight to 1 AM of the first Monday each month except December".

Edit: cron expressions for all examples:

* 11-12 * * mon
* 9-17 * * tue
* 8-10 * * wed
0-29 11 * * wed
* 12-16 * * wed
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
  • That seems to be the right thing for us. Thx! Now we look for JAVA and Objective-C libraries to do the converting... http://stackoverflow.com/questions/4469276/convert-cron-expression-into-nice-description-strings-is-there-a-library-for-jav – OneWorld Dec 17 '10 at 09:50
  • SORRY! I had to unmark your answer. Because cron expression can't describe "Wed 8:00-11:30, Wed 12:00-17:00" because they separate minutes and hours. You just can say 0-30 8-11,12-17 * * Wed * which means "8:00-8:30,9:00-9:30,..." AND describing the 3 example entries in my question in one cron expression isn'T supported either ;( – OneWorld Dec 17 '10 at 12:51
  • @OneWorld, you need more than one expression, this is allowed in cron. – Dour High Arch Dec 17 '10 at 18:36
  • Ok. Could u provide me an example, how to code the example from my question? – OneWorld Dec 17 '10 at 21:52
0

I would use the number of milliseconds since midnight. That's fairly standard, as in JavaScript and other languages you can easily add a number of milliseconds to a given time in order to get another time, or create a time-span object from a number of milliseconds.

Domenic
  • 110,262
  • 41
  • 219
  • 271