4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/jamm/time_util.rb', line 4
def self.relative_time_to_iso(relative_time)
return relative_time if iso_format?(relative_time)
quantity, unit = relative_time.split
quantity = quantity.to_i
case unit.downcase
when 'second', 'seconds'
time_delta = quantity
when 'minute', 'minutes'
time_delta = quantity * 60
when 'hour', 'hours'
time_delta = quantity * 60 * 60
when 'day', 'days'
time_delta = quantity * 60 * 60 * 24
when 'week', 'weeks'
time_delta = quantity * 60 * 60 * 24 * 7
else
raise ArgumentError, "Unknown time unit: #{unit}"
end
iso_time = Time.now + time_delta
iso_time.strftime('%Y-%m-%dT%H:%M:%SZ')
end
|