ruby on rails - Calculate difference in days ActiveSupport:TimeWithZone in the most "rubyish" style? -


I am feeling that someone is answering any other question which gives me the answer but I am with no luck This simple issue is not doing the search.

I have an active record with Deteipple property I give it as an ActiveSupport: TimeWeath Zone I know I can not compare the time on that date. Because there is no area in it, so I have to use time. Makes sense.

Am I thinking that the style is the "cleaner" way of reducing it to 86400 and dividing it?

What do I do here:

  ((time.son.new - myActiveRecord.visit_date) / 86400) .to_i  

Works, but I think I'm missing something. Should I compare, casting or alter casting, or is it really the typical way to do this in the railways?

P> One thing you do to make it more readable Can:

  ((Time.zone.now - myActiveRecord.visit_date) / 1.day) .to_i  

Edit:

Actually you can get rid of a set of brackets:

  (Time.zone.now - myActiveRecord.visit_date) .to_i / 1. day  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -