Module: Trenni::Formatters::RelativeTime

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

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trenni/formatters/relative_time.rb', line 29

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