Reputation: 5603
I have the following code:
puts 12.months.ago.month
Currently, this displays 5
, for May since it's May 1st.
I need to spoof the date to make Rails think that it is yesterday, April 30th, so that the above will display 4
. I am running this on my local machine - I tried changing my computers date/time, but it didn't work as intended.
Any thoughts?
Upvotes: 0
Views: 86
Reputation: 37409
class Time
class << self
alias :orig_now :now
def now
orig_now - 1.day
end
end
end
Time.now
# => 2014-04-30 16:35:01 +0300
puts 12.months.ago.month
# => 4
Upvotes: 3
Reputation: 73639
Why don't you do something like following:
puts (12.months.ago - 1.day).month # returns 4
Upvotes: 0