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

Subreddit.DateCreated should have a bigger datatype #25

Closed
voigt opened this issue Nov 13, 2016 · 4 comments
Closed

Subreddit.DateCreated should have a bigger datatype #25

voigt opened this issue Nov 13, 2016 · 4 comments
Labels

Comments

@voigt
Copy link

voigt commented Nov 13, 2016

From subreddit.go#21

type Subreddit struct {
[...]
	DateCreated float32 `json:"created_utc"`
[...]
}

DateCreated float32 is to small for the timestamps the Reddit APi provides. Example:

  • Created Timestamp provided by API: 1478970533
  • Geddit is reducing this to: 1.4789705e+09 which is 1478970500

Which is 33 sec difference! I'd suggest to use int32 (-2147483648 to 2147483647) or uint32 (0 to 4294967295; since its a unix timestamp we wont need negative values).

However, since this repo hasn't been updated for a year now I have low hopes this will be changed. Nevertheless - I like the simplicity of geddits approach and its totally sufficient for my needs.

@jzelinskie jzelinskie added the bug label Nov 13, 2016
@jzelinskie
Copy link
Owner

Yes, this repo is a bit old, so I can't quite remember why float32 was chosen for timestamps.

Can you prove they are only ever integers? If so, I'll gladly change the data type to uint32 else, float64 seems like the next best option.

@voigt
Copy link
Author

voigt commented Nov 14, 2016

Here you can find the spec for created_utc. However, since they return a Unix Timestamp as long the value shouldn't ever be uneven.

@jzelinskie
Copy link
Owner

It looks like the JSON package doesn't like having parsing JSON numbers that end with .0 into integers: https://play.golang.org/p/YS-RS4sCEu

Can you think of any alternatives besides using float64?

@voigt
Copy link
Author

voigt commented Nov 14, 2016

Well I think the reddit documentation is a bit misleading here. On the one hand side its declaring the create timestamps with long (which is an integer), on the other hand side its giving the example 1331042771.0.

Looking at the timestamps provided by the API there are only integers (excerpt from https://www.reddit.com/r/Kitten/new/.json):

created: 1479092723,
created_utc: 1479063923,
created: 1479013385,
created_utc: 1478984585,
created: 1478762837,
created_utc: 1478734037,
created: 1478295208,
created_utc: 1478266408,
created: 1478203594,
created_utc: 1478174794,
created: 1477991484,
created_utc: 1477962684,
created: 1477957928,
created_utc: 1477929128,
created: 1477945729,
created_utc: 1477916929,
created: 1477893208,
created_utc: 1477864408,
created: 1477804026,
created_utc: 1477775226,
created: 1477802989,
created_utc: 1477774189,
created: 1477794667,
created_utc: 1477765867,
created: 1477774270,
created_utc: 1477745470,
created: 1477541571,
created_utc: 1477512771,
created: 1477418550,
created_utc: 1477389750,
created: 1477344521,
created_utc: 1477315721,
created: 1477032785,
created_utc: 1477003985,
created: 1476754550,
created_utc: 1476725750,
created: 1476407847,
created_utc: 1476379047,
created: 1476314035,
created_utc: 1476285235,
created: 1475067606,
created_utc: 1475038806,
created: 1474764466,
created_utc: 1474735666,
created: 1474008823,
created_utc: 1473980023,
created: 1473990161,
created_utc: 1473961361,
created: 1473237761,
created_utc: 1473208961,

I think you are pretty save to use uint32.

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

2 participants