Skip to content

Commit

Permalink
Script for calculating the number of days from a given date
Browse files Browse the repository at this point in the history
  • Loading branch information
robmiller committed Oct 19, 2023
1 parent ee98e6a commit 99546a2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bin/daysfrom
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby

require "date"

num_days =
case ARGV[0]
when /^\d+$/
ARGV[0].to_i
else
abort "Usage: daysfrom NUMDAYS [STARTDATE]"
end

start_date =
case ARGV[1]
when /^(\d{4})-(\d{2})-(\d{2})$/
Date.new($1.to_i, $2.to_i, $3.to_i)
else
Date.today
end

end_date = start_date + num_days

puts "#{start_date.strftime("%F")} + #{num_days} days → #{end_date.strftime("%F")}"

0 comments on commit 99546a2

Please sign in to comment.