You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/models/academic_year.rb

25 lines
554 B

This file contains ambiguous Unicode characters!

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}"
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)