Module: ETL::CoreExtensions::Time::Calculations
- Included in:
- Time
- Defined in:
- lib/etl/core_ext/time/calculations.rb
Overview
Enables the use of time calculations within Time itself
Instance Method Summary collapse
- #fiscal_year(offset_month = 10) ⇒ Object
- #fiscal_year_month(offset_month = 10) ⇒ Object
- #fiscal_year_quarter(offset_month = 10) ⇒ Object
- #fiscal_year_week(offset_month = 10) ⇒ Object
- #fiscal_year_yday(offset_month = 10) ⇒ Object
- #quarter ⇒ Object
- #week ⇒ Object
Instance Method Details
#fiscal_year(offset_month = 10) ⇒ Object
29 30 31 |
# File 'lib/etl/core_ext/time/calculations.rb', line 29 def fiscal_year(offset_month=10) month >= offset_month ? year + 1 : year end |
#fiscal_year_month(offset_month = 10) ⇒ Object
21 22 23 24 25 |
# File 'lib/etl/core_ext/time/calculations.rb', line 21 def fiscal_year_month(offset_month=10) shifted_month = month - (offset_month - 1) shifted_month += 12 if shifted_month <= 0 shifted_month end |
#fiscal_year_quarter(offset_month = 10) ⇒ Object
26 27 28 |
# File 'lib/etl/core_ext/time/calculations.rb', line 26 def fiscal_year_quarter(offset_month=10) ((fiscal_year_month(offset_month) - 1) / 3) + 1 end |
#fiscal_year_week(offset_month = 10) ⇒ Object
16 17 18 19 20 |
# File 'lib/etl/core_ext/time/calculations.rb', line 16 def fiscal_year_week(offset_month=10) fyw = ((fiscal_year_yday(offset_month) - 1) / 7) + 1 fyw = 52 if fyw == 53 fyw end |
#fiscal_year_yday(offset_month = 10) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/etl/core_ext/time/calculations.rb', line 32 def fiscal_year_yday(offset_month=10) offset_days = 0 1.upto(offset_month - 1) { |m| offset_days += ::Time.days_in_month(m, year) } shifted_year_day = yday - offset_days shifted_year_day += 365 if shifted_year_day <= 0 shifted_year_day end |
#quarter ⇒ Object
13 14 15 |
# File 'lib/etl/core_ext/time/calculations.rb', line 13 def quarter ((month - 1) / 3) + 1 end |
#week ⇒ Object
8 9 10 11 12 |
# File 'lib/etl/core_ext/time/calculations.rb', line 8 def week cyw = ((yday - 1) / 7) + 1 cyw = 52 if cyw == 53 cyw end |