Skip to content

Commit b16de0d

Browse files
authored
Create script.rb
1 parent f6794b1 commit b16de0d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

script.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require 'time'
2+
require 'json'
3+
query = ARGV[0]
4+
d = query.split(/,\s*/).inject(0) { |acc, ts|
5+
t1, t2 = ts.split /\s*-\s*/
6+
t1 = Time.parse(t1)
7+
t2 = Time.parse(t2)
8+
d = (t2 - t1) / 60 / 60 # in hours
9+
acc += d
10+
acc
11+
}
12+
h = d.floor.to_i
13+
m = (d % 1 * 60).to_i
14+
data = {
15+
items: [
16+
{
17+
title: "Total duration: #{d} (#{h} hours #{m} minutes)",
18+
arg: "#{d} (#{h} hours #{m} minutes)"
19+
}
20+
]
21+
}
22+
puts data.to_json

0 commit comments

Comments
 (0)