dtv11049 2016-06-24 14:20
浏览 62
已采纳

如何订购平日周日(0),包括部分周?

I'm reading opening hours for libraries from a database, so I get returned something like:

{
   "5":{ // library ID
      "4":{ // interval ID
         "statement":"",
         "start_date":"5th Jan 2015",
         "end_date":"1st Mar 2015",
         "hours":[
            {
               "day_of_week":"Sun",
               "opening_time":"12am",
               "closing_time":"12am",
               "is_closed":true,
               "open_24hrs":false
            },
            {
               "day_of_week":"Mon",
               "opening_time":"9am",
               "closing_time":"5pm",
               "is_closed":false,
               "open_24hrs":false
            },
            {
               "day_of_week":"Tue",
               "opening_time":"9am",
               "closing_time":"5pm",
               "is_closed":false,
               "open_24hrs":false
            },

for each "regular" opening hours and the same for each "variation", where the interval may be anything from one day to seven days. (here I've already preprocessed the day numbers to short day names). I'm getting the data from PostGreSQL via AJAX/PHP. My question is, how can I properly order the days for variations when the intervals may be anything from one day to several weeks (but only hours for one week are stored for intervals one week or longer), and can begin at any day eg: Fri, Sat, Sun, Mon long weekend (in this case the day numbers are 5,6,0,1 and so come out ordered as Sun, Mon, Fri, Sat)?

My initial thoughts are:

  • check if interval is a full week
  • if not, check if Sunday is traversed
  • if not, easily order by number
  • if Sunday is traversed, get start day and order up to Sunday then reset to 0 (for Sunday) and continue to highest number before start day

But I'm wondering if this is all overkill and I can accomplish the same using an order by clause or similar, something like this: Possible to create a query that sorts by day of week? ?

Any thoughts much appreciated.

  • 写回答

1条回答 默认 最新

  • dter8514 2016-06-24 14:29
    关注

    I would order it like so:

    ORDER BY interval.start_date, hours.day_of_week, hours.opening_time
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。