v0.4.0
humane v0.4.0
Humane::TimeFormatter gains approximate: (additive, not breaking)
Humane::TimeFormatter.new(approximate: true).string(at: t - 15 * 3600, relative_to: t)
# => "about 15 hours ago"Defaults to false, so existing callers see no change. When true, buckets of an
hour or larger get an "about"/"in about" prefix -- the way ActionView's
distance_of_time_in_words does past its own "about" threshold -- signaling that the
bucket is a rounded value. Sub-hour buckets are untouched either way.
Ported from humane-swift's identically-named, identically-defaulted option
(v0.1.0). The intended use is a static render that can't refresh itself -- a web
response, a cached page -- where a precise-looking "15 hours ago" is more confident
than the underlying value actually is. Contexts that can re-render on demand (a
native app, a live-polling frontend) have no reason to reach for it; the plain,
Foundation-matching default is still the right choice there.
Ruby's version turned out simpler to implement than Swift's: string builds the bare
quantity phrase ("15 hours") before wrapping it in "X ago"/"in X", so prefixing
"about " at that point composes correctly for both directions automatically.
Swift's implementation has to post-process RelativeDateTimeFormatter's
already-complete phrase instead, since Foundation hands back the whole sentence at
once.
Upgrading
Nothing required -- approximate defaults false, matching every existing caller's
current behavior exactly.
scandalous's time_ago helper is the first real consumer, opting in with
approximate: true since its listing page is a static, non-refreshing render -- the
exact case this option exists for.