sqm-dashboards/app/models/academic_year.rb

24 lines
554 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# frozen_string_literal: true
class AcademicYear < ActiveRecord::Base
def self.find_by_date(date)
year = parse_year_range(date:)
AcademicYear.find_by_range("#{year.start}-#{year.end.to_s[2, 3]}")
end
def formatted_range
years = range.split('-')
"#{years.first} 20#{years.second}"
end
def self.parse_year_range(date:)
year = date.year
if date.month > 6
AcademicYearRange.new(year, year + 1)
else
AcademicYearRange.new(year - 1, year)
end
end
end
AcademicYearRange = Struct.new(:start, :end)