Module: XRB::Formatters::RelativeTime

Defined in:
lib/xrb/formatters/relative_time.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xrb/formatters/relative_time.rb', line 12

def self.included(base)
	base.map(Time) do |object, **options|
		current_time = options.fetch(:current_time) {Time.now}
		
		# Ensure we display the time in localtime, and show the year if it is different:
		if object.localtime.year != current_time.year
			object.localtime.strftime("%B %-d, %-l:%M%P, %Y")
		else
			object.localtime.strftime("%B %-d, %-l:%M%P")
		end
	end
end