time.ago uses larger units of time for time differences smaller than one unit. For example, if a commit was made 7 months ago, time.ago reports this as "1 year ago". I think that smaller units of time would be more useful, i.e. "7 months ago".
My proposed solution is to show smaller units when they are less than their roll-over value (60 minutes, 24 hours, 31 days, or 12 months). Once the roll-over value is reached the larger unit is used. For example, 11 months is reported as "11 months ago" and 12 months is reported as "1 year ago".
Changes made in this PR
Use smaller units when applicable (as described above)
Fix parameter names in ago.ts (now and compareTo were swapped)
Remove unused secondsBetween function
Cleaned up tests a bit
Possible issue
Time differences are rounded up before they are compared to their roll-over value. For example, 11.6 months is rounded up to 12 months and is therefore reported as "1 year ago". Maybe it would be better to display this as "11 months ago" or "12 months ago". I personally prefer "1 year ago" but I'm open to other opinions.
Overview
time.ago
uses larger units of time for time differences smaller than one unit. For example, if a commit was made 7 months ago,time.ago
reports this as "1 year ago". I think that smaller units of time would be more useful, i.e. "7 months ago".My proposed solution is to show smaller units when they are less than their roll-over value (60 minutes, 24 hours, 31 days, or 12 months). Once the roll-over value is reached the larger unit is used. For example, 11 months is reported as "11 months ago" and 12 months is reported as "1 year ago".
Changes made in this PR
now
andcompareTo
were swapped)secondsBetween
functionPossible issue
Time differences are rounded up before they are compared to their roll-over value. For example, 11.6 months is rounded up to 12 months and is therefore reported as "1 year ago". Maybe it would be better to display this as "11 months ago" or "12 months ago". I personally prefer "1 year ago" but I'm open to other opinions.