在Parse DB中存储营业时间

时间:2015-09-22 03:33:48

标签: parse-platform

在Parse.com上为某个位置存储营业时间需要一些基础设施方面的帮助,我已经尝试将其作为一个名为BusinessHours的单独类,其中每一行都有一个指向Location类的指针。对于1个位置,每周的每一天至少有7行,对象计数达到+10.000

data browser screenshot Class BusinessHours

比swift我这样做以确定该位置现在是否打开

        for hour in hours {
           if hour.isClosedAllDay {
             isOpen = "closed".localized
           }else{
            let now = NSDate()

            if  now.hasDayOffset(hour.weekday, closeWeekDay: hour.nextWeekday) {
                if hour.open != nil && hour.close != nil {
                    let open = now.hourDateFromString(hour.open!, offset: now.dayOpenOffset(hour.weekday, closeWeekDay: hour.nextWeekday))
                    let close = now.hourDateFromString(hour.close!, offset: now.dayCloseOffset(hour.weekday, closeWeekDay: hour.nextWeekday))
                    if now.isBetween(open, close: close) {

                        isOpen = "open".localized
                        timeOfBusiness = hour.time!
                        break
                    }
                }
            }
        }
    }

有没有更好的方法来做到这一点,而不仅仅是营业时间有数千行?我想在几小时内向位置类添加一个对象字段,但不知道这是否也是正确的方法。

2 个答案:

答案 0 :(得分:0)

根据您要如何编辑和更改详细信息以及每天多次打开时间的复杂程度,我会考虑不使用多个列和行。相反,您可以简单地将JSON字符串存储在包含所有必需详细信息的单个列中。

显然你无法使用它进行查询,所以如果你需要这样做,那么你需要保留更像当前解决方案的东西。

如果您不需要查询,或者您需要简单的查询,例如“它是否在星期一开放”,则需要一个由云代码支持的组合解决方案,以便应用程序不需要大量的JSON知识,可以很好地工作。例如,您可以在每天的常规开放时间中使用列,然后使用JSON中的详细信息,这样您就可以通过查询获得粗略的答案,然后在显示/使用结果之前检查确切的详细信息。

答案 1 :(得分:0)

我最终在我的Location类中名为businessHours的数组字段中执行此操作:

[
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":1,"weekday":1},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":2,"weekday":2},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":3,"weekday":3},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":4,"weekday":4},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":5,"weekday":5},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":6,"weekday":6},
    {"close":"20:00Z","open":"12:00Z","time":"09:00 - 17:00","isClosedAllDay":false,"nextWeekday":7,"weekday":7}
]

然后以NSDictionary循环遍历对象。

谢谢Wain!