I am working with some code that is highly timezone dependent and am struggling to get Timecop to work for me here. I am using Ruby 3.2, and make use of the in: keyword argument in Time.new and Time.now
When using Timecop, the in keyword doesn't seem to be supported.
# Time.new
require 'timecop'
Time.freeze(Time.new(2024, 9, 20)) do
puts Time.new # 2024-09-20 00:00:00 -0400
puts Time.new(in: "+04:00") # 2024-09-24 17:54:33 +0400
end
As you can see there, when using in: the time is no longer frozen.
Additionally, Time.now does not appear to support the in: keyword argument at all when using Timecop:
#Time.now
puts Time.now(in: "+04:00") #2024-09-24 17:56:42 +0400
require 'timecop'
puts Time.now(in: "+04:00") # timecop-0.9.10/lib/timecop/time_extensions.rb:13:in `now_with_mock_time': wrong number of arguments (given 1, expected 0) (ArgumentError)
I see where Ruby 3.1 support was added in v0.9.4 to support these keywords but it seems like something is missing. It looks like the Timecop implementation of now doesn't accept any arguments and in new calls out to new_without_mock_time if there are keyword arguments, even if no positional arguments are passed.
I am working with some code that is highly timezone dependent and am struggling to get Timecop to work for me here. I am using Ruby 3.2, and make use of the
in:keyword argument inTime.newandTime.nowWhen using Timecop, the
inkeyword doesn't seem to be supported.As you can see there, when using
in:the time is no longer frozen.Additionally,
Time.nowdoes not appear to support thein:keyword argument at all when using Timecop:I see where Ruby 3.1 support was added in v0.9.4 to support these keywords but it seems like something is missing. It looks like the Timecop implementation of
nowdoesn't accept any arguments and innewcalls out tonew_without_mock_timeif there are keyword arguments, even if no positional arguments are passed.