Created
August 30, 2011 14:50
-
-
Save kkosuge/1181070 to your computer and use it in GitHub Desktop.
だいたい何日以内みたいなの返すRailsのヘルパー
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FooHelper | |
def unclear_time(to_time, from_time = Time.now.change(:hour => 0)) | |
from_time = from_time.to_time if from_time.respond_to?(:to_time) | |
to_time = to_time.to_time if to_time.respond_to?(:to_time) | |
distance_in_minutes = (((to_time - from_time).abs)/60).round | |
case distance_in_minutes | |
when 0..4320 then "三日以内" | |
when 4321..10080 then "一週間以内" | |
when 10081..44640 then "一か月以内" | |
else "一ヶ月以上前" | |
end | |
end | |
end | |
<%= unclear_time(Time.now + 6.days) %> #=> "一週間以内" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment