Apply user's time zone in advanced filters for time data type [SCI-6585] (#3930)

This commit is contained in:
Alex Kriuchykhin 2022-03-10 13:49:09 +01:00 committed by GitHub
parent d777149865
commit 378fbb6b76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 14 deletions

View file

@ -18,22 +18,22 @@ class RepositoryTimeRangeValue < RepositoryDateTimeRangeValueBase
case filter_element.operator
when 'equal_to'
repository_rows.where("#{join_alias}.start_time::time = (?)::time AND #{join_alias}.end_time::time = (?)::time",
parameters['start_time'], parameters['end_time'])
Time.zone.parse(parameters['start_time']), Time.zone.parse(parameters['end_time']))
when 'unequal_to'
repository_rows
.where.not("#{join_alias}.start_time::time = (?)::time AND #{join_alias}.end_time::time = (?)::time",
parameters['start_time'], parameters['end_time'])
Time.zone.parse(parameters['start_time']), Time.zone.parse(parameters['end_time']))
when 'greater_than'
repository_rows.where("#{join_alias}.start_time::time > (?)::time", parameters['end_time'])
repository_rows.where("#{join_alias}.start_time::time > (?)::time", Time.zone.parse(parameters['end_time']))
when 'greater_than_or_equal_to'
repository_rows.where("#{join_alias}.start_time::time >= (?)::time", parameters['end_time'])
repository_rows.where("#{join_alias}.start_time::time >= (?)::time", Time.zone.parse(parameters['end_time']))
when 'less_than'
repository_rows.where("#{join_alias}.end_time::time < (?)::time", parameters['start_time'])
repository_rows.where("#{join_alias}.end_time::time < (?)::time", Time.zone.parse(parameters['start_time']))
when 'less_than_or_equal_to'
repository_rows.where("#{join_alias}.end_time::time <= (?)::time", parameters['start_time'])
repository_rows.where("#{join_alias}.end_time::time <= (?)::time", Time.zone.parse(parameters['start_time']))
when 'between'
repository_rows.where("#{join_alias}.start_time::time > (?)::time AND #{join_alias}.end_time::time < (?)::time",
parameters['start_time'], parameters['end_time'])
Time.zone.parse(parameters['start_time']), Time.zone.parse(parameters['end_time']))
else
raise ArgumentError, 'Wrong operator for RepositoryTimeRangeValue!'
end

View file

@ -14,19 +14,19 @@ class RepositoryTimeValue < RepositoryDateTimeValueBase
parameters = filter_element.parameters
case filter_element.operator
when 'equal_to'
repository_rows.where("#{join_alias}.data::time = ?", Time.zone.parse(parameters['time']))
repository_rows.where("#{join_alias}.data::time = (?)::time", Time.zone.parse(parameters['time']))
when 'unequal_to'
repository_rows.where.not("#{join_alias}.data::time = ?", Time.zone.parse(parameters['time']))
repository_rows.where.not("#{join_alias}.data::time = (?)::time", Time.zone.parse(parameters['time']))
when 'greater_than'
repository_rows.where("#{join_alias}.data::time > ?", Time.zone.parse(parameters['time']))
repository_rows.where("#{join_alias}.data::time > (?)::time", Time.zone.parse(parameters['time']))
when 'greater_than_or_equal_to'
repository_rows.where("#{join_alias}.data::time >= ?", Time.zone.parse(parameters['time']))
repository_rows.where("#{join_alias}.data::time >= (?)::time", Time.zone.parse(parameters['time']))
when 'less_than'
repository_rows.where("#{join_alias}.data::time < ?", Time.zone.parse(parameters['time']))
repository_rows.where("#{join_alias}.data::time < (?)::time", Time.zone.parse(parameters['time']))
when 'less_than_or_equal_to'
repository_rows.where("#{join_alias}.data::time <= ?", Time.zone.parse(parameters['time']))
repository_rows.where("#{join_alias}.data::time <= (?)::time", Time.zone.parse(parameters['time']))
when 'between'
repository_rows.where("#{join_alias}.data::time > ? AND #{join_alias}.data::time < ?",
repository_rows.where("#{join_alias}.data::time > (?)::time AND #{join_alias}.data::time < (?)::time",
Time.zone.parse(parameters['start_time']), Time.zone.parse(parameters['end_time']))
else
raise ArgumentError, 'Wrong operator for RepositoryTimeValue!'