0

This is one of those questions that I'm sure will have a quick answer but I can't seem to find it.

Using the Facebook Graph API, the opening hours for a business are returned in JSON using this format:

"hours": {
  "mon_1_open": 406800,
  "mon_1_close": 437400,
  "tue_1_open": 493200,
  "tue_1_close": 523800,
  "wed_1_open": 579600,
  "wed_1_close": 610200,
  "thu_1_open": 61200,
  "thu_1_close": 91800,
  "fri_1_open": 147600,
  "fri_1_close": 178200,
  "sat_1_open": 237600,
  "sat_1_close": 264600,
  "sun_1_open": 324000,
  "sun_1_close": 345600
}

The hours should be 0900 - 1730 weekdays, 1000-1730 Saturdays & 1000-1600 Sundays.

I can see there are 30600 seconds between opening and closing on weekdays, so it's a number of seconds since something, but I'm not sure since what.

What kind of time format is this, and how can I convert it into something usable in PHP?

Bonus: Why would they use a timestamp "since" something, seeing as the hours recur weekly?

2
  • I don't think PHP has a method to convert a number of seconds to hours,minutes,seconds, from the epoch or otherwise. You'll have to write one.
    – Jeremy
    Jun 10, 2011 at 12:57
  • I think the facebook graph api has a :date method instead of :time that's a little bit less of a hassle to use. Jun 10, 2011 at 13:07

1 Answer 1

2

I'm not sure what TimeZone you're in, but looking at it, hey all seem to be exact second counts originating from 00:00:00Z Thursday morning. I'd say that puts you at about the PST timezone.

3
  • Well I'm in the UK but OK. Is it odd that FB puts shop opening hours in this format?
    – Joe W
    Jun 10, 2011 at 13:00
  • @Joe: it's not a format I would use, but this is just a guess as to how it's derived. At any rate, since Thursday is the smallest value in the list and opening time happens to be exactly 17hrs after the origination value, that can certainly be used to generate a php method to determine the hours. I would definitely leave yourself a comment in that method to make sure you don't forget why you're adding 17hrs as an offset somewhere. Jun 10, 2011 at 13:04
  • Another thought is that it could be slightly opposite to my thinking. If the server originating the data is in PST, then it could be "adding time" in a westerly direction. PST->GMT is exactly 17hrs when DST is active if you travel west to get there. Jun 10, 2011 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.