Last week I had to write some code that manipulates dates (yet again). It’s something we do often at Burt for various reasons.
Since we normally work with timestamps we map almost every unit to the number of seconds it represents so there will be code like
MINUTE = 60 HOUR = 60 * MINUTE
When coding Rails, ActiveSupport gives you some really nice helper methods allowing you to write pretty code like
start = 3.days.ago
Since I couldn’t find a lightweight replacement for ActiveSupport within 30 minutes I decided to rock my own with the basic functionality I currently require and made it available.
Given you have a Time object, you can also use it to add and subtract seconds from the Time object
t = Time.utc(2011, 02, 23) start = t - 5.days
Hopefully someone else will find it useful