Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time.new with in: keyword argument does not return frozen time. #431

Open
mcfadden opened this issue Sep 24, 2024 · 2 comments · May be fixed by #432
Open

Time.new with in: keyword argument does not return frozen time. #431

mcfadden opened this issue Sep 24, 2024 · 2 comments · May be fixed by #432

Comments

@mcfadden
Copy link

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.

@joshuacronemeyer
Copy link
Collaborator

Hey there @mcfadden thanks for the bug report! You're right we have not implemented this new-ish feature of Ruby. Are you willing to create a PR? I'm the maintainer for Timecop. I consider this a high-priority issue and would be happy to support anyone who wants to implement this. If not we'll leave this issue open here for a bit and see if anyone in the community wants to take it on.

@mcfadden
Copy link
Author

Hey @joshuacronemeyer,

I'd love to make a PR for this. I plan to work on that in the later half of this week. If I have any issues I'll reach out to you here.

Thanks!

@mcfadden mcfadden linked a pull request Sep 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants