Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse time intervals in Ruby?

Tags:

time

parsing

ruby

I have time interval strings like 6:30 am – 2:30 pm or 5:30–11:00 pm (notice the omitted "pm" for the start time here) that I want to parse into Time objects in Ruby. Is there an elegant way to do that or do I have to catch all different cases manually?

like image 856
Ortwin Gentz Avatar asked Jun 19 '26 11:06

Ortwin Gentz


2 Answers

http://chronic.rubyforge.org? ;-)

like image 123
StuFF mc Avatar answered Jun 21 '26 02:06

StuFF mc


Perhaps using a time library like Chronic could help you?

like image 40
Jakob W Avatar answered Jun 21 '26 03:06

Jakob W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!