2014-07-17 38 views
0

我想使用助手distance_of_time_in_words,它工作正常,但天數不準確。單詞中的時間距離?

我有我的表:

t.datetime "start" 
t.datetime "end" 

而且我使用:

<%= distance_of_time_in_words(Time.now, @promotion.end) %> 

的事情是,我有促銷明天結束,但在我看來,它仍然說「 4天到結束「...

什麼可能是錯的?

+2

向我們顯示數據。 –

+1

@TheChamp我認爲這是內置的。 –

+0

[distance_of_time_in_words](http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words)幷包括它http://stackoverflow.com/a/9573793/1183537 – SuckerForMayhem

回答

0

可能是您的distance_of_time_in_words在您的情況下計算了錯誤的天數。例如,你不會指望它來計算41小時靜止1天,但它的作用:

helper.distance_of_time_in_words(41.hours+ 59.minutes+29.seconds) 
=> "1 day" 

看到它使用了,在這裏看中四捨五入原則: http://apidock.com/rails/ActionView/Helpers/DateHelper/distance_of_time_in_words

看到我的電子郵件到Rails核心,關於此行爲,請在此處:https://groups.google.com/forum/#!searchin/rubyonrails-core/distance_of_time_in_words/rubyonrails-core/VnfsO0TNTOI/-EKjN6Egr6cJ