Created
November 25, 2010 04:16
-
-
Save xn/714891 to your computer and use it in GitHub Desktop.
home_run failing with subtraction using ActiveSupport and DateTime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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