Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

24 hours in minutes in ruby on rails

How to convert 24.hours into minutes it gives me second.

1.9.3p392 :076 > 24.hours
=> 86400 seconds 

One NON-RUBY way is

1.9.3p392 :079 > 24*60
 => 1440 

Is there any ruby or rails way of doing this? i.e. 24.hours_in_minutes

like image 576
Manish Shrivastava Avatar asked Dec 12 '22 15:12

Manish Shrivastava


1 Answers

The most appropriate way to do this is probably:

24.hours / 1.minute

This way you keep the readability and clear intention of the 'ruby mindset'.

Of course, this will have a constant value so you should probably store it in an appropriately named constant (e.g. MINUTES_IN_A_DAY) rather than calculating it every time.

like image 199
DaveMongoose Avatar answered Jan 05 '23 18:01

DaveMongoose