Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a quick port. you may try:</p> <pre><code>def distance_of_time_in_words = { fromTime, toTime, includeSeconds, options -&gt; if(toTime==null) toTime = 0 if(includeSeconds==null) includeSeconds = false if(options==null) options = [] def distance_in_mins = (int)Math.round(Math.abs(toTime - fromTime)/60.0) def distance_in_seconds = (int)Math.round(Math.abs(toTime - fromTime)) switch (distance_in_mins) { case 0..1: if(distance_in_mins == 0) { return "less than 1 minute" } else { if (includeSeconds == false) return "${distance_in_mins} minute" } switch (distance_in_seconds) { case 0..4: return "less than 5 seconds" case 5..9: return "less than 10 seconds" case 10..19: return "less than 20 seconds" case 20..39: return "half a minute" case 40..59: return "less than 1 minute" default: return "1 minute" } case 2..44: return "${distance_in_mins} minutes" case 45..89: return "about an hour" case 90..1439: return "about ${Math.round(distance_in_mins / 60.0)} hours" case 1440..2879: return "a day" case 2880..43199: return "${Math.round(distance_in_mins / 1440)} days" case 43200..86399: return "a month" case 86400..525599: return "${Math.round(distance_in_mins / 43200)} months" case 525600..1051199: return "a year" default: return "over ${Math.round(distance_in_mins / 525600)} years" } } def d = new Date().time println distance_of_time_in_words(d, d + 10, true, []) println distance_of_time_in_words(d, d + 60, true, []) println distance_of_time_in_words(d, d + 35, true, []) println distance_of_time_in_words(d, d + 123, true, []) println distance_of_time_in_words(d, d + 400, true, []) println distance_of_time_in_words(d, d + 1300*60, true, []) println distance_of_time_in_words(d, d + 2000*60, true, []) println distance_of_time_in_words(d, d + 3.5*60*60*24, true, []) println distance_of_time_in_words(d, d + 32*60*60*24, true, []) println distance_of_time_in_words(d, d + 65*60*60*24, true, []) println distance_of_time_in_words(d, d + 1.5*12*30*60*60*24, true, []) println distance_of_time_in_words(d, d + 7*12*30*60*60*24, true, []) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload