Last Updated: December 26, 2018
·
1.542K
· jarrettgreen

Time for stfrtime to die.

Stamp Gem

https://github.com/jeremyw/stamp

Throw an example string at it, and it does the dirty work. No more %m, %Y, etc.

date = Date.new(2011, 6, 9)
date.stamp("March 1, 1999")         #=> "June  9, 2011"
date.stamp("Jan 1, 1999")           #=> "Jun  9, 2011"
date.stamp("Jan 01")                #=> "Jun 09"
date.stamp("Sunday, May 1, 2000")   #=> "Thursday, June  9, 2011"
date.stamp("Sun Aug 5")             #=> "Thu Jun  9"
date.stamp("12/31/99")              #=> "06/09/11"
date.stamp("DOB: 12/31/2000")       #=> "DOB: 06/09/2011"

1 Response
Add your response

In my mind, the most difficult part of the % formatters is the distinction between a 1 digit day/month vs. a 2 digit.

How would your example of 'date.stamp("12/31/99")' know whether I want a 1 or 2 digit month/day?

over 1 year ago ·