Module: HrLite::LeaveYear
- Defined in:
- lib/hr_lite/leave_year.rb
Overview
The leave year is the 12-month window balances live in. It starts on config.leave_year_start_month (1 = calendar year, 7 = July–June, the Indian travel-industry pattern). A year is identified by the calendar year its FIRST month falls in: with July starts, key 2026 spans 1 Jul 2026 – 30 Jun 2027.
Class Method Summary collapse
- .current_key ⇒ Object
-
.key_for(date) ⇒ Object
The key (integer label) of the leave year containing
date. -
.label(key) ⇒ Object
"2026" for calendar years, "2026–27" otherwise.
- .range(key) ⇒ Object
- .start_month ⇒ Object
Class Method Details
.current_key ⇒ Object
19 20 21 |
# File 'lib/hr_lite/leave_year.rb', line 19 def current_key key_for(Date.current) end |
.key_for(date) ⇒ Object
The key (integer label) of the leave year containing date.
15 16 17 |
# File 'lib/hr_lite/leave_year.rb', line 15 def key_for(date) date.month >= start_month ? date.year : date.year - 1 end |
.label(key) ⇒ Object
"2026" for calendar years, "2026–27" otherwise.
29 30 31 |
# File 'lib/hr_lite/leave_year.rb', line 29 def label(key) start_month == 1 ? key.to_s : format("%d–%02d", key, (key + 1) % 100) end |
.range(key) ⇒ Object
23 24 25 26 |
# File 'lib/hr_lite/leave_year.rb', line 23 def range(key) start = Date.new(key, start_month, 1) start..(start >> 12) - 1 end |