Module: Ace::Git::Atoms::TimeFormatter
- Defined in:
- lib/ace/git/atoms/time_formatter.rb
Overview
Pure functions for formatting timestamps as relative time strings Examples: “2h ago”, “1d ago”, “3w ago”
Constant Summary collapse
- SECONDS_PER_MINUTE =
Time constants for format_duration calculations
60- MINUTES_PER_HOUR =
60- HOURS_PER_DAY =
24- DAYS_PER_WEEK =
7- DAYS_PER_MONTH =
Simplified (actual avg ~30.44)
30- DAYS_PER_YEAR =
365- MONTHS_PER_YEAR =
12
Class Method Summary collapse
-
.relative_time(timestamp, reference_time: Time.now) ⇒ String
Convert an ISO8601 timestamp to relative time.
Class Method Details
.relative_time(timestamp, reference_time: Time.now) ⇒ String
Convert an ISO8601 timestamp to relative time
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ace/git/atoms/time_formatter.rb', line 25 def relative_time(, reference_time: Time.now) return "" if .nil? || (.is_a?(String) && .empty?) time = () return "" if time.nil? seconds_ago = (reference_time - time).to_i # Don't format future times (negative duration) return "" if seconds_ago < 0 format_duration(seconds_ago) end |