问题
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"}]
回答1:
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
回答2:
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.
来源:https://stackoverflow.com/questions/4459855/any-standard-format-to-describe-time-ranges-as-string-want-to-use-it-for-openin