# frozen_string_literal: true require 'active_support' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/time' class DateRange attr_reader :start, :stop def initialize(start: nil, stop: nil) @start = extract_date(start) @stop = extract_date(stop) end alias begin start alias :end stop def empty? start.blank? && stop.blank? end def present? !blank? end def start? start.present? end alias begin? start? def stop? stop.present? end alias :end? stop? private def extract_date(date) return nil if date.blank? Time.zone.parse(String(date)).to_date end end