1module DateTimeHelper
 
2  WAITING_FOR_KEYS = Hash.new(:other).merge(0 => :zero, 1 => :one)
 
3  TO_BE_DEBATED_KEYS = Hash.new(:other).merge(0 => :today, 1 => :tomorrow)
 
4
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
5  def short_date_format(date_time)
 
6    date_time && date_time.strftime("%-d %B %Y")
 
7  end
 
8
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
 9  def short_date_time_format(date_time)
 
10    date_time && date_time.strftime("%H:%M%P on %-d %B %Y")
 
11  end
 
  • BooleanParameter - has boolean parameter 'seconds' » reek
  • ControlParameter - is controlled by argument 'seconds' » reek
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 2 » saikuro
13  def date_time_format(date_time, seconds: false)
 
14    if seconds
 
15      date_time && date_time.strftime("%d-%m-%Y %H:%M:%S")
 
16    else
 
17      date_time && date_time.strftime("%d-%m-%Y %H:%M")
 
18    end
 
19  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
21  def date_format(date_time)
 
22    date_time && date_time.strftime("%d/%m/%Y")
 
23  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
25  def date_format_admin(date_time)
 
26    date_time && date_time.strftime("%d-%m-%Y")
 
27  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
29  def local_date_time_format(date_time)
 
30    date_time && date_time.in_time_zone.strftime("%d/%m/%Y %H:%M")
 
31  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
33  def last_updated_at_time(date_time)
 
34    date_time && date_time.in_time_zone.strftime("%H:%M %Z")
 
35  end
 
  • Complexity 2 » saikuro
37  def waiting_for_in_words(date, now = Time.current)
 
38    return unless date.present?
 
 
40    scope = :"petitions.waiting_for_in_words"
 
41    days  = ((now.end_of_day - date.end_of_day) / 86400.0).round
 
42    key   = WAITING_FOR_KEYS[days]
 
 
44    t(key, scope: scope, formatted_count: number_with_delimiter(days))
 
45  end
 
  • ManualDispatch - manually dispatches method call » reek
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 3 » saikuro
47  def api_date_format(date_time)
 
48    if date_time
 
49      if date_time.respond_to?(:getutc)
 
50        date_time.getutc.iso8601(3)
 
51      else
 
52        date_time.strftime("%Y-%m-%d")
 
53      end
 
54    end
 
55  end
 
  • Complexity 1 » saikuro
57  def scheduled_for_debate_in_words(date, today = Date.current)
 
58    scope = :"petitions.scheduled_for_debate_in_words"
 
59    days  = (date - today).to_i
 
60    key   = TO_BE_DEBATED_KEYS[days]
 
 
62    t(key, scope: scope, formatted_date: short_date_format(date))
 
63  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
65  def christmas_period?(today = Date.current)
 
66    Holiday.christmas?(today)
 
67  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
69  def easter_period?(today = Date.current)
 
70    Holiday.easter?(today)
 
71  end
 
72end