LoginSignup
1
1

More than 5 years have passed since last update.

シーケンシャルな日付を生成するスクリプト

Posted at

Usage

Usage: seq_date [options]
    -s yyyy-mm-dd
    -e yyyy-mm-dd

script

#!/usr/bin/env ruby
# encoding: utf-8

require 'date'
require 'optparse'

start_date = nil
end_date = nil

opt = OptionParser.new

opt.on('-s yyyy-mm-dd') {|v| start_date = v }
opt.on('-e yyyy-mm-dd') {|v| end_date = v }
opt.parse!(ARGV)

if start_date.nil?
  sd = Time.now.to_date
else
  sd = Date.parse(start_date)
end

if end_date.nil?
  ed = Time.now.to_date
else
  ed = Date.parse(end_date)
end

d = sd
while d <= ed
  puts d.to_s
  d = d.next_day
end
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1