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
How does rails know the current date? Need to spoof the date to yesterday
-
13-07-2023 - |
Domanda
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?
Soluzione
Altri suggerimenti
Why don't you do something like following:
puts (12.months.ago - 1.day).month # returns 4
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow