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

Proposal: Implement Tod::TimeOfDay#upto / Tod::TimeOfDay#step #89

Open
asayamakk opened this issue Oct 19, 2021 · 1 comment
Open

Proposal: Implement Tod::TimeOfDay#upto / Tod::TimeOfDay#step #89

asayamakk opened this issue Oct 19, 2021 · 1 comment

Comments

@asayamakk
Copy link

Proposal for new instance methods upto and/or step

These can be used as following cases

Tod::TimeOfDay('10:00').upto(Tod::TimeOfDay('11::00')) do |tod|
  puts tod
end
#=> 10:00::00, 10:00:01, 10:00:02, ...10:59:59, 11:00:00
Tod::TimeOfDay('10:00').step(Tod::TimeOfDay('11::00'), 60) do |tod|
  puts tod
end
#=> 10:00, 10:01, 10:02, ...10:59, 11:00

c.f.
https://rubydoc.info/stdlib/date/Date#step-instance_method
https://rubydoc.info/stdlib/date/Date#upto-instance_method

before working on implementation, I would like to hear a comment about this methods. Thank you!

@jackc
Copy link
Owner

jackc commented Oct 23, 2021

I don't have any objection in principle. But in practice you would need to think through what wrapping at midnight means. e.g. 23:59:58, 23:59:59, 00:00:00, 00:00:01. Does it violate any expected contracts of upto or step for the next step to be less than the previous?

I don't think it would be problem, but I haven't thought deeply about it either.

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

No branches or pull requests

2 participants