In particular, to add time (e.g. 11:40 + 00:30 = 12:10
) and check whether a time belongs to a range (e.g. (11:00..12:00).include?(11:30)
).
I understand that I can write a class, but maybe a solution already exists.
The built-in Time
class is not entirely what I want, because I am not interested in date-related features, which are built-in.
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- How to account for clock offsets in a distributed
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
ActiveSupport
's Numeric will help you.You can do:
You will need the
ActiveSupport
gem in yourGemfile
.As for checking if a time is in a range you can use #cover:
You can use
strftime
to format the time any way you want. If you want only the hour and minutes you can use this:Here is a link to the strftime docs