Chatwoot/app/helpers/date_range_helper.rb

20 lines
601 B
Ruby
Raw Normal View History

##############################################
# Helpers to implement date range filtering to APIs
# Include in your controller or service class where params is available
##############################################
module DateRangeHelper
def range
return if params[:since].blank? || params[:until].blank?
parse_date_time(params[:since])..parse_date_time(params[:until])
end
def parse_date_time(datetime)
return datetime if datetime.is_a?(DateTime)
return datetime.to_datetime if datetime.is_a?(Time) || datetime.is_a?(Date)
DateTime.strptime(datetime, '%s')
end
end