Module: Fortnight

Defined in:
lib/fortnight.rb,
lib/fortnight/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
# File 'lib/fortnight.rb', line 5

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#fortnight_in_wordsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fortnight.rb', line 39

def fortnight_in_words
  date = self.created_at.to_date
  month_begin = date.beginning_of_month
  half_month = month_begin.advance(days: 14)

  if date.day >= 1 && date.day <=15
    output = I18n.l(month_begin, format: :long)
    output << ' - '
    output << I18n.l(half_month.to_date, format: :long)
  else
    output = I18n.l((half_month + 1.day).to_date, format: :long)
    output << ' - '
    output << I18n.l(date.end_of_month, format: :long)
  end

  output
end