module Concerns::Competition::Dates::InstanceMethods

Public Instance Methods

all_year?() click to toggle source
# File app/models/competitions/concerns/competition/dates.rb, line 61
def all_year?
  true
end
date() click to toggle source
# File app/models/competitions/concerns/competition/dates.rb, line 15
def date
  if all_year?
    return self[:date]
  end

  if source_events.any?
    source_events.sort.first.date
  elsif parent
    parent.start_date
  else
    self[:date]
  end
end
date_range_long_s() click to toggle source
# File app/models/competitions/concerns/competition/dates.rb, line 49
def date_range_long_s
  if multiple_days?
    "#{start_date.strftime('%a, %B %d')} to #{end_date.strftime('%a, %B %d, %Y')}"
  else
    start_date.strftime('%a, %B %d')
  end
end
default_date() click to toggle source
# File app/models/competitions/concerns/competition/dates.rb, line 11
def default_date
  Time.zone.now.beginning_of_year
end
end_date() click to toggle source

Last day of year for date

# File app/models/competitions/concerns/competition/dates.rb, line 35
def end_date
  if all_year?
    return Time.zone.local(year).end_of_year
  end
  
  if source_events.present?
    source_events.sort.last.date
  elsif parent
    parent.end_date
  else
    Time.zone.local(year).end_of_year
  end
end
multiple_days?() click to toggle source
# File app/models/competitions/concerns/competition/dates.rb, line 57
def multiple_days?
  source_events.count > 1
end
start_date() click to toggle source

Same as date. Should always be January 1st

# File app/models/competitions/concerns/competition/dates.rb, line 30
def start_date
  date
end
valid_dates() click to toggle source

Assert start and end dates are first and last days of the year

# File app/models/competitions/concerns/competition/dates.rb, line 66
def valid_dates
  if all_year?
    if start_date.nil? || start_date != start_date.beginning_of_year
      errors.add "start_date", "must be January 1st, but was: '#{start_date}'"
    end
    if end_date.nil? || end_date != end_date.end_of_year
      errors.add "end_date", "must be December 31st, but was: '#{end_date}'"
    end
  end
  if start_date && end_date && start_date.to_date.year != end_date.to_date.year
    errors.add :date, "and end date must be in same year"
  end
end