Facebook changed time formatting
robbiet480 opened this issue · comments
Seems that Facebook has changed the timestamp formatting on at least some routes, such as /<post_id>
, to something resembling ISO8601. I have this code to parse it, I would submit a PR but not sure if its outside the scope of the project or if we should attempt to parse this new format in the existing code as part of decodeField
/decode
like we do for standard time.Time
already:
type FacebookISO8601 time.Time
func (it FacebookISO8601) MarshalJSON() ([]byte, error) {
return []byte(time.Time(it).Format(`"2006-01-02T15:04:05-0700"`)), nil
}
func (it *FacebookISO8601) UnmarshalJSON(data []byte) error {
t, err := time.ParseInLocation(`"2006-01-02T15:04:05-0700"`, string(data), time.UTC)
if err == nil {
*it = FacebookISO8601(t)
}
return err
}
I think it should be out of scope of this package. You can do what you show in the issue to decode the field as expected. There is no special time format related parser in this package right now.
I am still studying me from Indonesia my name is Sofyan.
I recently discovered a somewhat hidden feature of the Graph API. You can provide a param, date_format
with a PHP compatible date()
format string. Doing this allows me to make every request use time.RFC3339
(date_format=
Y-m-d\TH:i:sP
). I'm thinking about adding a new flag to Session
or maybe a global flag like Version
to allow setting the "default" date_format
param for all requests. That way, you could set it to RFC3339 and use the native time.Time
instead of having to use a custom implementation like mine above.
Thoughts on this @huandu? Default params to send on every request, the first and only one to start being date_format
?
LGTM.