class HgDateBreakup::Range
Public Class Methods
between(date1, date2)
click to toggle source
# File lib/hg_date_breakup.rb, line 8 def self.between(date1, date2) new(Date.parse(date1), Date.parse(date2)) end
Private Class Methods
new(date1, date2)
click to toggle source
# File lib/hg_date_breakup.rb, line 38 def initialize(date1, date2) @date1 = date1 @date2 = date2 @year_array = Array.new @month_array = Array.new @week_array = Array.new @day_array = Array.new end
Public Instance Methods
get_accurate()
click to toggle source
# File lib/hg_date_breakup_v1.rb, line 12 def get_accurate years, remaining_dates_year = get_years(@date1, @date2) months, remaining_dates_month = get_months(remaining_dates_year) weeks, remaining_dates_week = get_weeks(remaining_dates_month) days, remaining_dates_days = get_days(remaining_dates_week) output = { years: years, months: months, weeks: weeks, days: days } end
get_days()
click to toggle source
# File lib/hg_date_breakup.rb, line 30 def get_days get_day_array(@date1, @date2) output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array } end
get_months()
click to toggle source
# File lib/hg_date_breakup.rb, line 18 def get_months get_month_array(@date1, @date2) output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array } end
get_weeks()
click to toggle source
# File lib/hg_date_breakup.rb, line 24 def get_weeks get_week_array(@date1, @date2) output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array } end
get_years()
click to toggle source
# File lib/hg_date_breakup.rb, line 12 def get_years get_year_array(@date1, @date2) output = { years: @year_array, months: @month_array, weeks: @week_array, days: @day_array } end
Private Instance Methods
get_date_data(date)
click to toggle source
# File lib/hg_date_breakup.rb, line 174 def get_date_data(date) day_hash = { day: date.yday, month_day: date.mday, month: date.month, year: date.year, start_date: date, end_date: date } @day_array << day_hash new_date = date + 1.day move_to_date = false return new_date, move_to_date end
get_day_array(date, end_date)
click to toggle source
# File lib/hg_date_breakup.rb, line 135 def get_day_array(date, end_date) move_to_date = true # DAY if move_to_date date, move_to_date = get_date_data(date) end if date <= end_date get_day_array(date, end_date) end end
get_month_array(date, end_date)
click to toggle source
# File lib/hg_date_breakup.rb, line 86 def get_month_array(date, end_date) move_to_date = true # MONTH if move_to_date if date.beginning_of_month == date if date.end_of_month <= @date2 date, move_to_date = get_month_data(date) end end end # Week if move_to_date if date.beginning_of_week == date && date.end_of_week <= @date2 if date.beginning_of_week.month == date.end_of_week.month || date.end_of_week.end_of_month >= @date2 date, move_to_date = get_week_data(date) end end end # DAY if move_to_date date, move_to_date = get_date_data(date) end if date <= end_date get_month_array(date, end_date) end end
get_month_data(date)
click to toggle source
# File lib/hg_date_breakup.rb, line 156 def get_month_data(date) month_hash = { month: date.month, year: date.year, start_date: date, end_date: date.end_of_month } @month_array << month_hash new_date = date.end_of_month + 1.day move_to_date = false return new_date, move_to_date end
get_month_range(date1, date2, month_array, month_hash)
click to toggle source
# File lib/hg_date_breakup_v1.rb, line 189 def get_month_range(date1, date2, month_array, month_hash) next_month = (date1.end_of_month + 1.day) end_next_month = next_month.end_of_month if end_next_month <= date2 month = end_next_month.month start_date = next_month.beginning_of_month end_date = end_next_month month_hash = { month: month, year: end_next_month.year, start_date: start_date, end_date: end_date } month_array << month_hash get_month_range(next_month, date2, month_array, month_hash) end end
get_week_array(date, end_date)
click to toggle source
# File lib/hg_date_breakup.rb, line 116 def get_week_array(date, end_date) move_to_date = true # Week if move_to_date if date.beginning_of_week == date && date.end_of_week <= @date2 date, move_to_date = get_week_data(date) end end # DAY if move_to_date date, move_to_date = get_date_data(date) end if date <= end_date get_week_array(date, end_date) end end
get_week_data(date)
click to toggle source
# File lib/hg_date_breakup.rb, line 165 def get_week_data(date) week_hash = { week: date.cweek, month: date.month, year: date.year, start_date: date, end_date: date.end_of_week } @week_array << week_hash new_date = date.end_of_week + 1.day move_to_date = false return new_date, move_to_date end
get_week_range(date1, date2, week_array, week_hash)
click to toggle source
# File lib/hg_date_breakup_v1.rb, line 202 def get_week_range(date1, date2, week_array, week_hash) next_week = (date1.end_of_week + 1.day) end_next_week = next_week.end_of_week if end_next_week <= date2 week = end_next_week.cweek start_date = next_week.beginning_of_week end_date = end_next_week week_hash = { week: week, month: end_next_week.month, year: end_next_week.year, start_date: start_date, end_date: end_date } week_array << week_hash get_week_range(next_week, date2, week_array, week_hash) end end
get_year_array(date, end_date)
click to toggle source
# File lib/hg_date_breakup.rb, line 47 def get_year_array(date, end_date) move_to_date = true # YEAR if move_to_date if date.beginning_of_year == date if date.end_of_year <= @date2 date, move_to_date = get_year_data(date) end end end # MONTH if move_to_date if date.beginning_of_month == date if date.end_of_month <= @date2 date, move_to_date = get_month_data(date) end end end # Week if move_to_date if date.beginning_of_week == date && date.end_of_week <= @date2 if date.beginning_of_week.month == date.end_of_week.month || date.end_of_week.end_of_month >= @date2 date, move_to_date = get_week_data(date) end end end # DAY if move_to_date date, move_to_date = get_date_data(date) end if date <= end_date get_year_array(date, end_date) end end
get_year_data(date)
click to toggle source
# File lib/hg_date_breakup.rb, line 147 def get_year_data(date) year_hash = { year: date.year, start_date: date, end_date: date.end_of_year } @year_array << year_hash new_date = date.end_of_year + 1.day move_to_date = false return new_date, move_to_date end
get_year_range(date1, date2, year_array, year_hash)
click to toggle source
# File lib/hg_date_breakup_v1.rb, line 176 def get_year_range(date1, date2, year_array, year_hash) next_year = (date1.end_of_year + 1.day) end_next_year = next_year.end_of_year if end_next_year <= date2 year = end_next_year.year start_date = next_year.beginning_of_year end_date = end_next_year year_hash = { year: year, start_date: start_date, end_date: end_date } year_array << year_hash get_year_range(next_year, date2, year_array, year_hash) end end