From 428a0a86f049bbcb1dee8cacd2862b02b4aa17a8 Mon Sep 17 00:00:00 2001 From: Johannes Leers Date: Fri, 3 Nov 2017 10:33:26 +0100 Subject: [PATCH 1/2] Added timezone support for daterange --- lib/ajax-datatables-rails/datatable/column_date_filter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb index df2b659e..f0e54775 100644 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column_date_filter.rb @@ -21,8 +21,8 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - new_start = range_start.blank? ? DateTime.parse('01/01/1970') : DateTime.parse(range_start) - new_end = range_end.blank? ? DateTime.current : DateTime.parse("#{range_end} 23:59:59") + new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") table[field].between(OpenStruct.new(begin: new_start, end: new_end)) end From 65aa589b238999f23c0f3ba1de1f71f067ec04a6 Mon Sep 17 00:00:00 2001 From: Johannes Leers Date: Fri, 3 Nov 2017 11:19:42 +0100 Subject: [PATCH 2/2] Added timezone support for daterange --- .../datatable/column_date_filter.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column_date_filter.rb b/lib/ajax-datatables-rails/datatable/column_date_filter.rb index f0e54775..78a31fe3 100644 --- a/lib/ajax-datatables-rails/datatable/column_date_filter.rb +++ b/lib/ajax-datatables-rails/datatable/column_date_filter.rb @@ -21,8 +21,14 @@ def range_end # Do a range search def date_range_search return nil if empty_range_search? - new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) - new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") + + if Time.zone + new_start = range_start.blank? ? Time.zone.parse('01/01/1970') : Time.zone.parse(range_start) + new_end = range_end.blank? ? Time.current : Time.zone.parse("#{range_end} 23:59:59") + else + new_start = range_start.blank? ? DateTime.parse('01/01/1970') : DateTime.parse(range_start) + new_end = range_end.blank? ? DateTime.current : DateTime.parse("#{range_end} 23:59:59") + end table[field].between(OpenStruct.new(begin: new_start, end: new_end)) end