Module: ActivateAdmin::DatetimeHelpers

Defined in:
lib/datetime_helpers.rb

Instance Method Summary collapse

Instance Method Details

#compact_time_ago(t) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/datetime_helpers.rb', line 22

def compact_time_ago(t)
  d = Time.now - t
  if d < 1.day
    time_ago_in_words(t) + ' ago'
  elsif d < 3.days
    t.strftime('%A') + " at #{t.to_s(:time)}"
  else
    t
  end
end

#datetime_select_tags(name, options) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/datetime_helpers.rb', line 4

def datetime_select_tags(name, options)
  v = options[:value] || Time.zone.now
  c = options[:class]
  id = options[:id]
  s = []
  s << "<style>.datetime select { width: auto }</style>"
  s << "<span id=\"#{id if id}\" class=\"datetime #{c if c}\">"
  s << select_tag(:"#{name}[day]", :options => (1..31).to_a, :selected => v.day )
  s << select_tag(:"#{name}[month]", :options => Date::MONTHNAMES[1..-1].each_with_index.map { |x,i| [x,i+1] }, :selected => v.month)
  s << select_tag(:"#{name}[year]", :options => (2012..2020).to_a, :selected => v.year )
  s << '@'
  s << select_tag(:"#{name}[hour]", :options => (0..23).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.hour ) 
  s << ':'
  s << select_tag(:"#{name}[min]", :options => (0..59).to_a.map { |x| [x < 10 ? "0#{x}" : x,x] }, :selected => v.min )
  s << '</span>'
  s.join(' ')
end