Please take a look at [this gist](https://gist.github.com/trustedtomato/aed8437e6ba768027dade774b47886a7). It's basically the same thing but simpler & resolves the timestamp.