Calculate difference in days ActiveSupport:TimeWithZone in the most “rubyish” style?

后端 未结 3 1640
无人共我
无人共我 2020-12-23 16:50

I have a feeling someone is going to point me to another question that answers this but I\'ve been searching with no luck over this simple issue.

I have a Activereco

3条回答
  •  温柔的废话
    2020-12-23 17:15

    One thing you can do to make it more readable is:

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

    Edit:

    Actually you can get rid of one set of the brackets with:

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

提交回复
热议问题