From b16de0d77ec10c69e89b4f12444a31adf54fd9ca Mon Sep 17 00:00:00 2001 From: Kensuke Nagae Date: Tue, 4 Oct 2022 15:05:06 +0900 Subject: [PATCH] Create script.rb --- script.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 script.rb diff --git a/script.rb b/script.rb new file mode 100644 index 0000000..3c64a43 --- /dev/null +++ b/script.rb @@ -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