Class: Effective::TableRows::DateField

Inherits:
Effective::TableRow show all
Defined in:
app/models/effective/table_rows/date_field.rb

Instance Attribute Summary

Attributes inherited from Effective::TableRow

#builder, #name, #options, #template

Instance Method Summary collapse

Methods inherited from Effective::TableRow

#controller_namespace, #hint, #initialize, #label, #label_content, #to_html, #tr_class, #value

Constructor Details

This class inherits a constructor from Effective::TableRow

Instance Method Details

#contentObject



7
8
9
# File 'app/models/effective/table_rows/date_field.rb', line 7

def content
  nice_date(value)
end

#nice_date(value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/effective/table_rows/date_field.rb', line 11

def nice_date(value)
  return unless value.respond_to?(:strftime)

  label = value.strftime("%b %-d, %Y")
  full = value.strftime("%A %b %-d, %Y %l:%M%P %z")

  now = Time.zone.now

  distance = if (now > value)
    template.distance_of_time_in_words(now, value) + ' ago'
  else
    template.distance_of_time_in_words(value, now) + ' from now'
  end

  (:span, label, title: full + ' (' + distance + ')')
end