JonathanSimmons
JonathanSimmons

Reputation: 1558

Distance_of_time_in_words

I am using distance_of_time_in_words with the expanded gem dotiw as follows:

<%= distance_of_time_in_words(@client.report_missing_after.days, Date.today, false, except: ["hours","minutes"])  %>

If @client.report_missing_after were to equal 7 the code above would return "7 Days" as expected. This works fine if @client.report_missing_after equals 1-28, but, when I reach 29 suddenly the output looks like:

87847649280000 years and 238878720000 days

which is not correct.

I can't figure out where I'm going wrong here. Help?

UPDATE:

Per a comment I simply tried to pass the first argument as an integer and it still doesn't work:

<%= distance_of_time_in_words(29.days ,0, false, except: ["hours","minutes"]) %>

Upvotes: 0

Views: 1274

Answers (2)

JonathanSimmons
JonathanSimmons

Reputation: 1558

Turns out distance_of_time_in_words works out better when you use it properly and by properly I mean with a timestamp and not a datetime object.

This is what ended up working for me:

<%= distance_of_time_in_words(Time.now, Time.now+29.days, false, except ["hours","minutes"]) %>

Upvotes: 0

muttonlamb
muttonlamb

Reputation: 6501

Have you tried passing in the days explicitly?

29.days

var.days

Upvotes: 1

Related Questions