Class: Safai::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/safai/date.rb

Class Method Summary collapse

Class Method Details

.smart_date(i) ⇒ Object



22
23
24
25
# File 'lib/safai/date.rb', line 22

def self.smart_date(i)
  return "" if i.blank?
  i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y")
end

.smart_due_date(i) ⇒ Object



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

def self.smart_due_date(i)
  if i == nil
    return ""
  elsif i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone"
    i = i.to_date
    i_display = i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y")
  end
  if Date.today == i
    return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Today</span>"
  elsif i - Date.today == 1
    return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Tomorrow</span>"
  elsif Date.today - i > 0.9
    return "<span style=\"background-color:#FFC7C7;padding:0px 2px 0px 2px;\">" +  i_display + "</span>"
  elsif Date.today - i < 1
    return "<span style=\"background-color:#D2FFCC;padding:0px 2px 0px 2px;\">" +  i_display + "</span>"
  end
  return i_display
end