Reno, NV    +1 (800)0 621-0871

Go back

Development

Trusting Tools Too Much

  |  August 23, 2012

This morning, we had a ticket regarding the publish times of posts in a site that was using Radiant CMS. The clue we had was that the publish time and the created_at time were different – which meant that somewhere, the published_at is being set and saved in the db without UTC. I searched the code for a good hour or so for terms like “published_at”, “publish!”, “timezone”, “TimeZone”, “local”, “utc”, etc. to no avail. I still couldn’t find where it is happening. We already had a debugger right before saving it and here are the results:

(rdb:2) page.created_at
nil
(rdb:2) page.published_at
nil
(rdb:2) page.save
true
(rdb:2) page.created_at
Thu, 23 Aug 2012 10:30:36 EST +10:00
(rdb:2) page.published_at
Thu, 23 Aug 2012 10:30:36 EST +10:00
(rdb:2) page.reload
#
(rdb:2) page.created_at
Thu, 23 Aug 2012 10:30:36 EST +10:00
(rdb:2) page.published_at
Thu, 23 Aug 2012 18:30:36 EST +10:00
As you can see, right after saving, the published_at is the same as created_at, but after reloading, we see it change! I checked the db structure and I didn’t see anything different. At that point, thoughts on Radiant bugs flew into my brain.

“Maybe this is a Radiant bug?” “No it couldn’t be – I searched already and no one seemed to point it out.” “It has to be – it’s not in our code!” “No, if it was a bug, somebody surely would have fixed it”

Needless to say, I trusted Radiant too much to even check. Finally, I did relent and tried opening the Radiant gem. And there it was. Right before saving, Radiant used Time.now when saving published_at. From this StackOverflow answer it is mentioned that Time.now used the machine’s OS no matter what you set in Rail’s config.time_zone. This was the flaw! And it WAS in Radiant and not in our code. Having fixed it, I checked Radiant’s github again and saw that it was fixed at some point. We were just using an older version – it probably was fixed without people knowing about it.

So there you have it. Don’t trust your tools too much and always consider EVERY option.