Module: HrLite::FinancialYear

Defined in:
lib/hr_lite/financial_year.rb

Overview

The Indian financial year runs 1 April – 31 March. Three places worked this out for themselves (the slip's year-to-date sums, the TDS projector and the rate card); it lives here once so they cannot drift apart.

Constant Summary collapse

START_MONTH =
4

Class Method Summary collapse

Class Method Details

.before?(date, other) ⇒ Boolean

True when date falls in an earlier FY than other.

Returns:

  • (Boolean)


22
23
24
# File 'lib/hr_lite/financial_year.rb', line 22

def self.before?(date, other)
  start_for(date) < start_for(other)
end

.label(date) ⇒ Object

"2026-27" — for warnings and screens, never for arithmetic.



16
17
18
19
# File 'lib/hr_lite/financial_year.rb', line 16

def self.label(date)
  start = start_for(date)
  "#{start.year}-#{format('%02d', (start.year + 1) % 100)}"
end

.start_for(date) ⇒ Object

First day of the FY containing date. March 2027 belongs to the year that opened on 1 April 2026.



10
11
12
13
# File 'lib/hr_lite/financial_year.rb', line 10

def self.start_for(date)
  year = date.month >= START_MONTH ? date.year : date.year - 1
  Date.new(year, START_MONTH, 1)
end