Module: Gitlab::Database::DateTime
- Defined in:
- lib/gitlab/database/date_time.rb
Instance Method Summary collapse
-
#subtract_datetimes(query_so_far, start_time_attrs, end_time_attrs, as) ⇒ Object
Find the first of the ‘end_time_attrs` that isn’t ‘NULL`.
- #subtract_datetimes_diff(query_so_far, start_time_attrs, end_time_attrs) ⇒ Object
Instance Method Details
#subtract_datetimes(query_so_far, start_time_attrs, end_time_attrs, as) ⇒ Object
Find the first of the ‘end_time_attrs` that isn’t ‘NULL`. Subtract from it the first of the `start_time_attrs` that isn’t NULL. ‘SELECT` the resulting interval along with an alias specified by the `as` parameter.
Note: the interval is returned as an INTERVAL type.
11 12 13 14 15 |
# File 'lib/gitlab/database/date_time.rb', line 11 def subtract_datetimes(query_so_far, start_time_attrs, end_time_attrs, as) diff_fn = subtract_datetimes_diff(query_so_far, start_time_attrs, end_time_attrs) query_so_far.project(diff_fn.as(as)) end |
#subtract_datetimes_diff(query_so_far, start_time_attrs, end_time_attrs) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/gitlab/database/date_time.rb', line 17 def subtract_datetimes_diff(query_so_far, start_time_attrs, end_time_attrs) Arel::Nodes::Subtraction.new( Arel::Nodes::NamedFunction.new("COALESCE", Array.wrap(end_time_attrs)), Arel::Nodes::NamedFunction.new("COALESCE", Array.wrap(start_time_attrs)) ) end |