Skip to content

v0.5.0

Latest

Choose a tag to compare

@woodie woodie released this 10 Jul 20:19

humane v0.5.0

TimeFormatter now matches ActionView's bucket table exactly (through "1 day")

Humane::TimeFormatter.new(approximate: true).string(at: t - (44 * 60 + 30), relative_to: t)
# => "about 1 hour ago"

#string used to divide raw seconds independently per unit (seconds -> minutes ->
hours -> days), which let rounding carry across a bucket boundary on its own --
59:59:59 rounded to "60 minutes ago" instead of "1 hour ago". It now computes
distance_in_minutes (seconds/60, rounded once) and buckets off that, the same way
ActionView's distance_of_time_in_words does. That's what produces its specific,
non-obvious cutoffs: the "about 1 hour" bucket starts at 44 minutes 30 seconds (not
60:00), and "about 2 hours" starts at 89:30, not 90:00.

Two output changes, both additive to the API (no new keyword args):

  • include_seconds: false's collapse cutoff moved from 60 seconds to 30 seconds,
    matching the first row of ActionView's table. "45 seconds ago" is now
    "1 minute ago" instead of "less than a minute ago".
  • approximate narrowed from "about" on any bucket >= 1 hour to exactly the
    hour-scale buckets (1 hour, and 2..24 hours). ActionView's own table has no "about
    1 day", so neither does this anymore -- approximate: true on a 30-hour-old
    timestamp is now "1 day ago", not "about 1 day ago".

Scoped through the "1 day" row of ActionView's table -- week/month/year buckets are
out of scope, matching this library's "narrow, not full-featured" intent. See
humane-ruby issue #1 for the
source table this ports, and docs/COMMENTS.md for the full boundary-by-boundary
rationale.

humane (Go) and humane-swift picked up the identical table change in the same
session -- humane-swift's TimeFormatter moved off RelativeDateTimeFormatter as
its bucketing source in the process, since Foundation's own rounding doesn't hit
these specific cutoffs.

Upgrading

No API changes. Two output changes to check for if you depend on exact wording
below 90 seconds or on approximate's day-scale output -- see above.
scandalous's time_ago helper (the only known approximate: true consumer) is
unaffected: its documented usage is hour-scale ("about 14 hours ago"), not
day-scale.