Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facebook changed time formatting #95

Closed
robbiet480 opened this issue Jan 27, 2018 · 4 comments
Closed

Facebook changed time formatting #95

robbiet480 opened this issue Jan 27, 2018 · 4 comments
Labels

Comments

@robbiet480
Copy link
Contributor

robbiet480 commented Jan 27, 2018

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
}
@huandu
Copy link
Owner

huandu commented Jan 27, 2018

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.

@1sofyan
Copy link

1sofyan commented Feb 2, 2018

I am still studying me from Indonesia my name is Sofyan.

@huandu huandu closed this as completed Feb 4, 2018
@robbiet480
Copy link
Contributor Author

robbiet480 commented May 10, 2018

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?

@huandu
Copy link
Owner

huandu commented May 11, 2018

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants