Skip to content

Instantly share code, notes, and snippets.

View davidrzuluaga's full-sized avatar
👨‍💻
Focusing

David R Zuluaga davidrzuluaga

👨‍💻
Focusing
View GitHub Profile
@RicharCor
RicharCor / application_helper.rb
Last active January 12, 2019 23:03
Time ago in words a español
module ApplicationHelper
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
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
distance_in_seconds = ((to_time - from_time).abs).round
case distance_in_minutes
when 0..1
return (distance_in_minutes == 0) ? 'menos de un minuto' : '1 minuto' unless include_seconds