Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Created September 6, 2013 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwgoldman/6458771 to your computer and use it in GitHub Desktop.
Save samwgoldman/6458771 to your computer and use it in GitHub Desktop.
require "active_support/all"
now = Date.current
# => Thu, 05 Sep 2013
now - 2.months - 5.days + 2.months + 5.days == now
# => false
now - 2.months - 5.days + 5.days + 2.months == now
# => true
@PaulOstazeski
Copy link

require "active_support/all"                                                   
# => true
a,b = 2.times.map { Date.current }
# => [Thu, 05 Sep 2013, Thu, 05 Sep 2013]
a,b = a - 2.months, b - 2.months
# => [Fri, 05 Jul 2013, Fri, 05 Jul 2013]
a,b = a - 5.days, b - 5.days
# => [Sun, 30 Jun 2013, Sun, 30 Jun 2013]
a,b = a + 2.months, b + 5.days
# => [Fri, 30 Aug 2013, Fri, 05 Jul 2013]
a,b = a + 5.days, b + 2.months
# => [Wed, 04 Sep 2013, Thu, 05 Sep 2013]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment