How can I store a time value, specifically only hour and minute in Firebase?

∥☆過路亽.° 提交于 2021-01-27 07:28:30

问题


I don't need this time associated with any date. In fact, I don't want it associated with a specific date. It's more so associated with a generic day of the week. Monday, Saturday, etc.

For example, your local coffee shop sets their hours for Monday based on the fact that it is a Monday. Not based on it being May 22, 2017 or May 29, 2017, etc.

I could do something like...

"Local Coffee Shoppe": 
{
    "availability": 
    {
        "monday":
        {
            "start":
            {
                "hour": 7,
                "minute": 30
            },
            "end":
            {
                "hour": 21,
                "minute": 0
            }
        }
    }
}

This would mean the Local Coffee Shoppe is open Mondays from 7:30am to 9:00pm.

Is this the best way to achieve this? All times would be stored in UTC for example, with conversion happening client side.

EDIT1: Just realized there is a hole in this approach. It doesn't cover establishments that are open past midnight. To combat this, maybe each day just stores "start" and then "duration"...

    "monday":
    {
        "start":
        {
            "hour": 7,
            "minute": 30
        },
        "duration":
        {
            "hour": 13,
            "minute": 30
        }
    }

So it is open for 13 hours and 30 minutes past 7:30am. I.E. 9:00pm.


回答1:


I would recommend just storing timestamps and extracting as you suggested, that would be a good approach, this would also allow you to already have the code to expand your use case if you want.



来源:https://stackoverflow.com/questions/44228573/how-can-i-store-a-time-value-specifically-only-hour-and-minute-in-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!