Module: Interage::DateTimeHelper

Included in:
ApplicationHelper
Defined in:
lib/interage/date_time_helper.rb

Instance Method Summary collapse

Instance Method Details

#business_day?(date) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/interage/date_time_helper.rb', line 13

def business_day?(date)
  Holidays.on(date, :br).empty? && date.to_date.workday?
end

#business_days_from_now(days = 2) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/interage/date_time_helper.rb', line 5

def business_days_from_now(days = 2)
  date = days.to_i.business_days.from_now.to_date

  return l(date) if business_day?(date)

  business_days_from_now(days + 1)
end

#current_dayObject



43
44
45
# File 'lib/interage/date_time_helper.rb', line 43

def current_day
  Date.current.day
end

#current_day_nameObject



39
40
41
# File 'lib/interage/date_time_helper.rb', line 39

def current_day_name
  l(Date.current, format: '%A')
end

#current_monthObject



51
52
53
# File 'lib/interage/date_time_helper.rb', line 51

def current_month
  Date.current.strftime('%b')
end

#current_month_nameObject



31
32
33
# File 'lib/interage/date_time_helper.rb', line 31

def current_month_name
  month_name(Date.current)
end

#current_month_yearObject



47
48
49
# File 'lib/interage/date_time_helper.rb', line 47

def current_month_year
  "#{current_month} / #{current_year}"
end

#current_yearObject



55
56
57
# File 'lib/interage/date_time_helper.rb', line 55

def current_year
  Date.current.year
end

#format_date(date, date_format = :date_time) ⇒ Object



17
18
19
20
21
# File 'lib/interage/date_time_helper.rb', line 17

def format_date(date, date_format = :date_time)
  return if date.blank?

  l(date, format: date_format)
end

#format_datetime(date, date_format = '%d/%m/%Y %H:%M') ⇒ Object



27
28
29
# File 'lib/interage/date_time_helper.rb', line 27

def format_datetime(date, date_format = '%d/%m/%Y %H:%M')
  format_date(date, date_format)
end

#format_time(time) ⇒ Object



23
24
25
# File 'lib/interage/date_time_helper.rb', line 23

def format_time(time)
  time.strftime('%H:%M') if time.present?
end

#month_name(date) ⇒ Object



35
36
37
# File 'lib/interage/date_time_helper.rb', line 35

def month_name(date)
  date.to_date.strftime('%b')
end