Skip to content

Commit

Permalink
Create script.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanny authored Oct 4, 2022
1 parent f6794b1 commit b16de0d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions script.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'time'
require 'json'
query = ARGV[0]
d = query.split(/,\s*/).inject(0) { |acc, ts|
t1, t2 = ts.split /\s*-\s*/
t1 = Time.parse(t1)
t2 = Time.parse(t2)
d = (t2 - t1) / 60 / 60 # in hours
acc += d
acc
}
h = d.floor.to_i
m = (d % 1 * 60).to_i
data = {
items: [
{
title: "Total duration: #{d} (#{h} hours #{m} minutes)",
arg: "#{d} (#{h} hours #{m} minutes)"
}
]
}
puts data.to_json

0 comments on commit b16de0d

Please sign in to comment.