27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/general_diff.rb', line 27
def call(start_time, end_time, **opts)
results = []
end_time = end_time.to_time
opts = slice(opts, [:round_mode])
y_delta = years_diff(start_time, end_time, **opts)
results << y_delta
past_time = start_time.to_time + y_delta * SECONDS_IN_INTERVAL[:years]
m_delta = end_time > past_time ? months_diff(past_time, end_time, **opts) : 0
results << m_delta
past_time += m_delta * SECONDS_IN_INTERVAL[:months]
w_delta = end_time > past_time ? weeks_diff(past_time, end_time, **opts) : 0
results << w_delta
past_time += w_delta * SECONDS_IN_INTERVAL[:weeks]
d_delta = end_time > past_time ? days_diff(past_time, end_time, **opts) : 0
results << d_delta
past_time += d_delta * SECONDS_IN_INTERVAL[:days]
h_delta = end_time > past_time ? hours_diff(past_time, end_time, **opts) : 0
results << h_delta
past_time += h_delta * SECONDS_IN_INTERVAL[:hours]
m_delta = end_time > past_time ? minutes_diff(past_time, end_time, **opts) : 0
results << m_delta
past_time += m_delta * SECONDS_IN_INTERVAL[:minutes]
s_delta = end_time > past_time ? seconds_diff(past_time, end_time, **opts) : 0
results << s_delta * SECONDS_IN_INTERVAL[:seconds]
Hash[INTERVALS.zip(results)]
end
|