Chatwoot/app/helpers/date_range_helper.rb
Sojan Jose dd9d5e410c
feat: Add CSAT response APIs (#2503)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
2021-06-29 20:59:41 +05:30

19 lines
601 B
Ruby

##############################################
# 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