Class: Date

Inherits:
Object
  • Object
show all
Includes:
ErrorHelper
Defined in:
lib/creative_rails_utilities/date.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorHelper

included, #raise_positive_number_only, #raise_start_date_before_end_date

Class Method Details

.build_date_array(start_date, end_date) ⇒ Object



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

def self.build_date_array(start_date, end_date)
  start_date = start_date.to_date
  end_date   =  end_date.to_date

  raise_start_date_before_end_date if (start_date > end_date)

  date_array = []
  processable_date = start_date.dup
  while processable_date <= end_date
    date_array << processable_date
    processable_date = processable_date.tomorrow
  end

  return date_array
end

Instance Method Details

#array_with_pre_churn_limit(count_of_additional_days) ⇒ Object



34
35
36
37
38
39
# File 'lib/creative_rails_utilities/date.rb', line 34

def array_with_pre_churn_limit(count_of_additional_days)
  explicit_limit_date = (self + count_of_additional_days.days)
  now = Time.zone.now.to_date
  cutoff_date = (explicit_limit_date > now ? now.yesterday : explicit_limit_date)
  return Date.build_date_array(self, cutoff_date)
end

#build_date_array(date) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/creative_rails_utilities/date.rb', line 20

def build_date_array(date)
  date = date.to_date

  if self < date
    start_date = self
    end_date = date
  else
    start_date = date
    end_date = self
  end

  return Date.build_date_array(start_date, end_date)
end