module Lucky::TimeHelpers

Direct including types

Defined in:

lucky/page_helpers/time_helpers.cr

Instance Method Summary

Instance Method Detail

def distance_of_time_in_words(from : Time, to : Time) : String #

Returns a String with approximate distance in time between from and to.

distance_of_time_in_words(Time.utc(2019, 8, 14, 10, 0, 0), Time.utc(2019, 8, 14, 10, 0, 5))
# => "5 seconds"
distance_of_time_in_words(Time.utc(2019, 8, 14, 10, 0), Time.utc(2019, 8, 14, 10, 25))
# => "25 minutes"
distance_of_time_in_words(Time.utc(2019, 8, 14, 10), Time.utc(2019, 8, 14, 11))
# => "an hour"
distance_of_time_in_words(Time.utc(2019, 8, 14), Time.utc(2019, 8, 16))
# => "2 days"
distance_of_time_in_words(Time.utc(2019, 8, 14), Time.utc(2019, 10, 4))
# => "about a month"
distance_of_time_in_words(Time.utc(2019, 8, 14), Time.utc(2061, 10, 4))
# => "almost 42 years"

[View source]
def time_ago_in_words(from : Time) : String #

[View source]
def time_from_now_in_words(to : Time) : String #

Returns a String with approximate distance in time between current moment and future date.

time_from_now_in_words(Time.utc(2022, 8, 30)) # => "about a year"
# gives the same result as:
distance_of_time_in_words(Time.utc, Time.utc(2022, 8, 30)) # => "about a year"

See more examples in #distance_of_time_in_words.


[View source]