FQL and business hours - facebook

I'm querying information from a Facebook page for a small business using FQL and I'm trying to parse the business hours. The numbers I am getting back seem to represent seconds but I'm not sure when the epoch is. Wednesday and Thursday are the most confusing - open on Thursday is "57600" which would be 16 hours in seconds which would make 4pm Wednesday the epoch, but the closing hours on Wednesday - far past 4- are in the 600,000+ range.
Mon: 8:15am-12pm and 1pm - 5pm Tue: 8am-12pm and 1pm - 5pm Wed: 8am-12pm and 1pm - 9pm Thur:8am-12pm and 1pm - 5pm Fri:8am-12pm and 1pm - 5pm Sat:8am-12pm and 1pm - 5pm
<hours>
<mon_1_open>404100</mon_1_open>
<mon_1_close>417600</mon_1_close>
<tue_1_open>489600</tue_1_open>
<tue_1_close>504000</tue_1_close>
<wed_1_open>576000</wed_1_open>
<wed_1_close>590400</wed_1_close>
<thu_1_open>57600</thu_1_open>
<thu_1_close>72000</thu_1_close>
<fri_1_open>144000</fri_1_open>
<fri_1_close>158400</fri_1_close>
<sat_1_open>230400</sat_1_open>
<sat_1_close>244800</sat_1_close>
<sun_1_open>0</sun_1_open>
<sun_1_close>0</sun_1_close>
<mon_2_open>421200</mon_2_open>
<mon_2_close>435600</mon_2_close>
<tue_2_open>507600</tue_2_open>
<tue_2_close>522000</tue_2_close>
<wed_2_open>594000</wed_2_open>
<wed_2_close>622800</wed_2_close>
<thu_2_open>75600</thu_2_open>
<thu_2_close>90000</thu_2_close>
<fri_2_open>162000</fri_2_open>
<fri_2_close>176400</fri_2_close>
<sat_2_open>248400</sat_2_open>
<sat_2_close>262800</sat_2_close>
<sun_2_open>0</sun_2_open>
<sun_2_close>0</sun_2_close>
</hours>
If I change it to simply 8am-5pm Monday to Saturday I get an equally confusing response from FB
<hours>
<mon_1_open>403200</mon_1_open>
<mon_1_close>435600</mon_1_close>
<tue_1_open>489600</tue_1_open>
<tue_1_close>522000</tue_1_close>
<wed_1_open>576000</wed_1_open>
<wed_1_close>608400</wed_1_close>
<thu_1_open>57600</thu_1_open>
<thu_1_close>90000</thu_1_close>
<fri_1_open>144000</fri_1_open>
<fri_1_close>176400</fri_1_close>
<sat_1_open>230400</sat_1_open>
<sat_1_close>262800</sat_1_close>
<sun_1_open>0</sun_1_open>
<sun_1_close>0</sun_1_close>
<mon_2_open>0</mon_2_open>
<mon_2_close>0</mon_2_close>
<tue_2_open>0</tue_2_open>
<tue_2_close>0</tue_2_close>
<wed_2_open>0</wed_2_open>
<wed_2_close>0</wed_2_close>
<thu_2_open>0</thu_2_open>
<thu_2_close>0</thu_2_close>
<fri_2_open>0</fri_2_open>
<fri_2_close>0</fri_2_close>
<sat_2_open>0</sat_2_open>
<sat_2_close>0</sat_2_close>
<sun_2_open>0</sun_2_open>
<sun_2_close>0</sun_2_close>
</hours>
Am I missing some defacto standard time representation? How would someone go about parsing this as a legitimate time of day?

The Unix epoch is the time 00:00:00 UTC on 1 January 1970. Any time you see the term "epoch" used in relation to computer-based time, that's usually what it means.
In UTC, 404100 is Mon, 05 Jan 1970 16:15:00 GMT. Or, in the PST timezone, Mon, 05 Jan 1970 08:15:00 PST, which is the time you're expecting. Ignore the date; it's irrelevant, anyways.
You can test what I'm describing using this Epoch Converter.

Related

Extracting epoch from two different days yields same result

If I run this query on my database
SELECT EXTRACT('epoch' FROM age('2021-01-01'::date, '2019-12-01'::date))
The result is 34149600.
But then if I try with 2019-12-02 (one day more)
SELECT EXTRACT('epoch' FROM age('2021-01-01'::date, '2019-12-02'::date))
The result is exactly the same 34149600!
As if the seconds passed from 02 december 2019 to 01 january 2021 are the same as the seconds passed from 01 december 2019 to 01 january 2021.
Why is this? I've already tried the above code with timezones on 00:00:00+00 timezone for all dates (for 1st january 2021, 1st december 2019 and 2nd december 2021), and it gives the same result
Obviously, I would have expected the epoch to be different, around 3600*24 of difference (seconds in a day).
The similar results come from the age() function which returns an interval with years, months, days. In such an interval, 1 month = 30 days, so their conversions in seconds are similar.
You will get the expected result with
SELECT extract(epoch from ('2021-01-01'::timestamp - '2019-12-01'::timestamp)) => 34300800.000000
SELECT extract(epoch from ('2021-01-01'::timestamp - '2019-12-02'::timestamp)) => 34214400.000000

Handling Daylight Saving Time for scheduling purposes

I am working with an API that generates time periods based on a configured set of parameters.
So for example, I can specify I want 12 one month periods starting Jan 1st at midnight, and therefore the API will generate 12 monthly periods
01 Jan 2016 00:00:00 – 31 Jan 2016 23:59:59
01 Feb 2016 00:00:00 – 28 Feb 2016 23:59:59
Through to
01 Dec 2016 00:00:00 – 31 Dec 2016 23:59:59
Now the API expects a start date param supplied for the sequence of periods to be an ISO formatted string in UTC. So I’m currently in the UK, therefore if I choose to start the monthly periods from Jan 1st 2016 this would be 2016-01-01T00:00:00Z and is what I supply to the API call I am making to say when the first instance of my monthly periods should begin.
So now if I view the start and end dates of the generated monthly periods via the API, I will see them come back as
2016-01-01T00:00:00Z - 2016-01-31T23:59:59Z
2016-02-01T00:00:00Z - 2016-02-28T23:59:59Z
Etc to
2016-12-01T00:00:00Z - 2016-12-31T23:59:59Z
Something struck me about these generated periods and that is I want them to begin at midnight for where I currently am, but a period that is affected by GMT Daylight Time, so say my April period will look like so in the generated period from the API
2016-04-01T00:00:00Z - 2016-04-30T23:59:59Z
Parsing the start date for the above into a date object for viewing in the client (on my machine) will show up as
Fri Apr 01 2016 01:00:00 GMT+0100 (GMT Daylight Time)
So it’s saying that period starts at 1am and not midnight.
Now say if I wanted 12 months to be generated from 1st Jun when Daylight Savings is in effect.
My client side code currently will supply a start date to the API of 2016-05-31T23:00:00Z. This causes the API to generate start dates for each monthly period as being
2016-05-31T23:00:00Z - 2016-06-31T22:59:59Z (June Period)
2016-06-31T23:00:00Z - 2016-07-31T22:59:59Z (July)
Etc to
2017-04-30T23:00:00Z - 2017-05-31T22:59:59Z (May)
But now for a period that is not in GMT Daylight Time, so Jan for example it will show up as
2016-12-31T23:00:00Z - 2017-01-31T22:59:59Z
Meaning my client will see that start date as
Sat Dec 31 2016 23:00:00 GMT+0000 (GMT Standard Time)
So not Jan 1st at 00:00
Does this suggest that the API should know about the users timezone so the period generation logic in the API can factor this is when calculating the start and end dates?
Maybe I'm over thinking things here?!
The only real question I see here is:
Does this suggest that the API should know about the users timezone so the period generation logic in the API can factor this is when calculating the start and end dates?
In general, the answer is YES. Any time you are mapping calendar dates back to specific instants in time, then by definition you must involve time zones. That time zone can be that of the user's, or of some specific business location, or fixed to UTC, but they indeed part of the logic.
Consider that not every calendar date has a valid local "midnight" in every time zone. An example is 2015-10-18 in Sao Paulo Brazil, where the first moment of that day was 1:00 AM due to their spring-forward daylight saving time transition. There are many other examples of this around the world.
The only way to avoid the problem entirely is to not deal in specific times. If you are only working with whole dates, then your code can certainly compute the exact dates of each month without knowing anything about time zones. 2016-01-01 through 2016-01-31 has no awareness of time or time zone. It's only when you try to ask what the current date is, or if now is within that range, or if some other specific instant in time is within that range that you have to start thinking about time zones.

Define time intervals using day of week/month (ISO 8601?)

I want to define time intervals like:
Each week, from Monday 12:00 a.m. to Sunday 11:59:59 p.m.
Each day from 12:00 a.m. to 11:59:59 p.m.
Each month from the first day of the month 12:00 a.m. to the last day of the month 11:59:59 p.m.
Is this possible using ISO 8601, or any other well-known standard?
You're asking for repeating periods of a week, a day and a month. The period should be defined as P1W, P1D or P1M respectively. Given an appropriate start point, I'd expect things such as the following to work:
R/2015-02-16/P1W - repeating weekly periods, starting on a known Monday.
R/2015-02-17/P1D - repeating daily periods, starting today
R/2015-02/P1M - repeating monthly periods, starting this month
These should be ISO 8601 compliant.

Summer time calculation

Currently i have missing understand on summertime, below is my context:
start summer time: June/1/2014 0h
end summer time: November/29/2014 0h
assume at the time 23h59 of November/29/2014 after passing => 0h00 November/30/2014 => the summertime will be minus 1 (-1) => 23h00 of November/29/2014 => it still under summer time (June/1/2014 0h - November/29/2014 0h)
So is my calculation above correct ?
Your misunderstanding is ignoring the fact that the time zone is part of the timestamp, and is necessary to make a timestamp in local time unambiguous.
If summer time ends at 00:00 at the beginning of November 30th, then the series of timestamps is:
2014-11-29 23:59:58 XST
2014-11-29 23:59:59 XST
2014-11-29 23:00:00 XWT
2014-11-29 23:01:01 XWT
[...]
2014-11-29 23:59:59 XWT
2014-11:30 00:00:00 XWT
(where "XST" is the summer timezone and "XWT" is the winter timezone). "2014-11-29 23:00:00 XST" and "2014-11-29 23:00:00 XWT" are two different times, one hour apart.
If you are given a local time between 2014-11-29 23:00 and 2014-11-30 00:00 without an indicator of whether it's XST or XWT, then it's impossible to turn it into a unique timestamp.

UNIX Timestamp or something else?

I have a field containing what should be a UNIX time stamp. As an example one value is 1408675380
Now when I do various online conversions, it shows the right day (22nd August) but shows the incorrect time. It should be around 21:00 or so but instead shows 02:43:00 GMT
Likewise, 1408676520 shows the correct day (22nd August) but instead of showing a time of around 22:00/23:00 it shows 03:02:00 GMT
I have no control over the data at all - just wondering if there's something obvious I'm missing?
1408849260 - Sunday, August 24th 2014, 03:01:00 (GMT) - Correct day, around 18 hours too early
1408850640 - Sunday, August 24th 2014, 03:24:00 (GMT) - Correct day, around 18 hours too early
Thanks,
JJ
Is your data in some other timezone than GMT ? something like GMT-5 (america west cost maybe ?)