Skip to content

Instantly share code, notes, and snippets.

@xn
Created November 25, 2010 04:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save xn/714891 to your computer and use it in GitHub Desktop.
home_run failing with subtraction using ActiveSupport and DateTime
irb(main):001:0> require 'active_support/core_ext'
=> true
irb(main):002:0> x = Date.new(2001)
=> Mon, 01 Jan 2001
irb(main):003:0> x - 1.second
=> 2000-12-31 23:59:59 -0500
irb(main):004:0> y = DateTime.new(2001)
=> Mon, 01 Jan 2001 00:00:00 +0000
irb(main):005:0> y - 1.second
TypeError: expected numeric or date
from (irb):5:in `-'
from (irb):5
from /usr/local/bin/irb:12:in `<main>'
irb(main):006:0> y + -1.second
=> Sun, 31 Dec 2000 00:00:00 +0000
irb(main):007:0> y + 1.second
=> Tue, 02 Jan 2001 00:00:00 +0000
irb(main):008:0> y + -1.week
=> Mon, 12 Feb 0345 00:00:00 +0000
irb(main):009:0> y + -1.day
=> Tue, 12 Jun 1764 00:00:00 +0000
irb(main):010:0> y + -1.hour
=> Sat, 23 Feb 1991 00:00:00 +0000
irb(main):011:0> y + -1.minute
=> Thu, 02 Nov 2000 00:00:00 +0000
irb(main):012:0> y
=> Mon, 01 Jan 2001 00:00:00 +0000
irb(main):013:0> y + -1.year
=> Thu, 25 Mar -84401 00:00:00 +0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment