Class: FiscalYear::YearToDate
- Inherits:
-
Object
- Object
- FiscalYear::YearToDate
- Defined in:
- lib/fiscal_year/year_to_date.rb
Class Method Summary collapse
-
.half_range_by(date) ⇒ Range<Date>
The range of the half year to date.
-
.quarter_range_by(date) ⇒ Range<Date>
The range of the quarter to date.
-
.range_by(date) ⇒ Range<Date>
The range of the year to date.
-
.year_month_pairs(date) ⇒ Array<Array<Integer>, Array<Integer>>
The passed year and month pairs.
Class Method Details
.half_range_by(date) ⇒ Range<Date>
Returns the range of the half year to date.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fiscal_year/year_to_date.rb', line 55 def half_range_by(date) year = date.year month = date.month beginning_year = if Half.first?(month) FiscalYear.cross_year_month?(month) ? year - 1 : year else Half.cross_year_in_half?(Half.second) ? FiscalYear.decrease_year_by_month(year, month) : year end half_method = Half.first?(month) ? :first : :second Date.parse("#{beginning_year}/#{Half.public_send(half_method).first}/01")..date.end_of_month.to_date end |
.quarter_range_by(date) ⇒ Range<Date>
Returns the range of the quarter to date.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fiscal_year/year_to_date.rb', line 79 def quarter_range_by(date) year = date.year month = date.month quarter_method = %i[first? second? third? fourth?] .filter { |method_name| FiscalYear::Quarter.public_send(method_name, month) } .first.to_s.gsub("?", "").to_sym quarter = Quarter.public_send(quarter_method) beginning_year = Quarter.cross_year_in_quarter?(quarter) ? FiscalYear.decrease_year_by_month(year, month) : year Date.parse("#{beginning_year}/#{quarter.first}/01")..date.end_of_month.to_date end |
.range_by(date) ⇒ Range<Date>
Returns the range of the year to date.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fiscal_year/year_to_date.rb', line 14 def range_by(date) year = date.year month = date.month if FiscalYear.cross_year_month?(month) Date.parse("#{year - 1}/#{FiscalYear.config.start_month}/01")..date.end_of_month.to_date else Date.parse("#{year}/#{FiscalYear.config.start_month}/01")..date.end_of_month.to_date end end |
.year_month_pairs(date) ⇒ Array<Array<Integer>, Array<Integer>>
Returns the passed year and month pairs.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fiscal_year/year_to_date.rb', line 36 def year_month_pairs(date) month = date.month month_index = FiscalYear.months.index(month) months = FiscalYear.months[(0..month_index)] raise StandardError if months.nil? [date.year].product(months).map do |e| [FiscalYear.decrease_year_by_month(e.first, e.second), e.second] end end |