Class: ReeDatetime::WeeksDiff

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/weeks_diff.rb

Constant Summary collapse

WEEK_SECONDS =
60.0 * 60 * 24 * 7

Instance Method Summary collapse

Instance Method Details

#call(start_time, end_time, **opts) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/weeks_diff.rb', line 21

def call(start_time, end_time, **opts)
  s_delta = end_time.to_time.to_i - start_time.to_time.to_i

  raise ArgumentError, "start_time bigger than end_time" if s_delta < 0
  
  w_delta = s_delta / WEEK_SECONDS
  opts[:precision] = 0

  round_helper(
    w_delta,
    **slice(opts, [:precision, :round_mode])
  ).to_i
end