4

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.

chris P
  • 6,359
  • 11
  • 40
  • 84
  • Are you looking for a SQL solution or something else? – Tim Biegeleisen May 28 '17 at 14:58
  • 3
    @TimBiegeleisen No just essentially the best way to do it. I suppose I could store an entire date and then just strip out the hour and minute, but that seems ambiguous and confusing. Just wondering if this is the best course. – chris P May 28 '17 at 14:59
  • @TimBiegeleisen actually I just realized there is a hole in this approach. It wouldn't work for establishments that stay open past 12am – chris P May 28 '17 at 15:01
  • From what I understand, Firebase is based off an old version of Postgres. Assuming there is a time type, you could store those points in time using that. Then, e.g. add them to timestamps to get an actual timestamp for the opening date. – Tim Biegeleisen May 28 '17 at 15:02
  • 4
    did you ever end up with a solution to this problem? – Boss Nass Aug 14 '17 at 09:29

1 Answers1

-3

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.