Project

General

Profile

Bug #11621 ยป date.rb

andreionut (Andrei Balcanasu), 10/26/2015 03:54 PM

 
require 'date'

p Date.today - 7
# => #<Date: 2015-10-19 ((2457315j,0s,0n),+0s,2299161j)>
p Date.today -7
# => #<Date: 2015-10-26 ((2457322j,0s,0n),+0s,2299161j)>
p Date.today-7
# => #<Date: 2015-10-19 ((2457315j,0s,0n),+0s,2299161j)>

p (Date.today - 7) == (Date.today-7)
# => true
p (Date.today -7) == (Date.today-7)
# => false
p (Date.today - 7) == (Date.today- 7)
# => true
p (Date.today - 7) == (Date.today -7)
# => false

days = 5
p (Date.today - days) == (Date.today -days)
# => false
p (Date.today - days) == (Date.today-days)
# => true

now = Date.today
p (now - 7) == (now-7)
# => true
p (now -7) == (now-7)
# => true
p (now - 7) == (now- 7)
# => true
p (now - 7) == (now -7)
# => true

p (DateTime.now -7) == (DateTime.now - 7)
# => false

p (Date.new(2001,2,3) - 7) == (Date.new(2001,2,3) -7)
# => true
p (Date.jd(2451944) - 7) == (Date.jd(2451944) -7)
# => true
p (Date.ordinal(2001,34) - 7) == (Date.ordinal(2001,34) -7)
# => true
p (Date.commercial(2001,5,6) - 7) == (Date.commercial(2001,5,6) -7)
# => true
p (Date.parse('2001-02-03') - 7) == (Date.parse('2001-02-03') -7)
# => true
p (Date.strptime('03-02-2001', '%d-%m-%Y') - 7) == (Date.strptime('03-02-2001', '%d-%m-%Y') -7)
# => true
p (Time.new(2001,2,3).to_date - 7) == (Time.new(2001,2,3).to_date -7)
# => date.rb:30:in `to_date': wrong number of arguments (1 for 0) (ArgumentError)
# from date.rb:30:in `<main>'
    (1-1/1)