Skip to content

Instantly share code, notes, and snippets.

@jsl
Last active December 20, 2015 19:49
Show Gist options
  • Save jsl/6186375 to your computer and use it in GitHub Desktop.
Save jsl/6186375 to your computer and use it in GitHub Desktop.
Rails date subtraction different on Mac OS and Linux
# Using ruby-2.0.0-p247, Rails console
# On Mac:
2.0.0p247 :006 > Date.today - Date.yesterday
=> 1
2.0.0p247 :007 > (Date.today - Date.yesterday).class
=> Fixnum
# On Ubuntu 12.04
2.0.0p247 :009 > Date.today - Date.yesterday
=> (1/1)
2.0.0p247 :010 > (Date.today - Date.yesterday).class
=> Rational
# When I try to unload ActiveSupport extensions, I still see different behavior for Date:
# Mac OS X:
2.0.0-p247 :001 > Date.ancestors
=> [Date, Comparable, Object, Kernel, BasicObject]
# Linux
2.0.0p247 :002 > Date.ancestors
=> [Date, Object, Kernel, BasicObject]
# Something is still monkey-patching my Date? The initializers are also different - on OS X it takes three params (Y, M, D) and on Linux I get:
2.0.0p247 :006 > ::Date.new(2011, 01, 03)
ArgumentError: wrong number of arguments (3 for 0)
# OS X:
2.0.0-p247 :005 > Date.new(2001, 1, 1)
=> #<Date: 2001-01-01 ((2451911j,0s,0n),+0s,2299161j)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment