PHP DateTime Class
With as much time as I spend talking about Rails, you’d think that’s all I do. In fact, Bitscribe - like many companies, I’m sure - maintains a number of apps which predate Rails. My team and I often find ourselves bring concepts from Rails (and other frameworks; we have a few Django fans here, for example) into our the frameworks used on these apps. A sort of backport, if you will.
In that vein, a coworker of mine created a timestamp manipulation class for PHP. Dates come out of the database as strings, which are easy enough to turn into time_t timestamps; but hard to manipulate or do comparisons on. I often find myself falling back to doing the manipulation in SQL, since Postgres has excellent date/time manipulation; but this is pretty ugly, and basically impossible to unit test.
Since it is a standalone class, it was easy to extract from the framework, so I suggested he post it on the Bitscribe open source page, which he did. Here it is: BDateTime. Next time you find yourself manipulating timestamps through mktime(), strtotime(), and (heaven forbid) regular expressions, try BDateTime out instead.