This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 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}"
def self.parse_year_range(date:)
year = date.year
if date.month > 6
AcademicYearRange.new(year, year + 1)
else
AcademicYearRange.new(year - 1, year)
AcademicYearRange = Struct.new(:start, :end)