Closed voigt closed 7 years ago
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.
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?
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
.
From
subreddit.go#21
DateCreated float32
is to small for the timestamps the Reddit APi provides. Example:1478970533
1.4789705e+09
which is1478970500
Which is 33 sec difference! I'd suggest to use
int32
(-2147483648 to 2147483647) oruint32
(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.