Sha256: f98349d2f34097a4c473800b2171368ee0910b5ecc6bb8b8b1ae12446182cc95

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

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

require "date"
require "pp"
require "optparse"

## option analysis
OPTIONS = {}
op = OptionParser.new
op.on("-t time", "--time=val", "Time indication."){|v| OPTIONS[:time] = v}
op.on("-s string", "--string=val", "String just after DateTime."){|v| OPTIONS[:string] = v}
op.on("-i num", "--indent=num", "Indicate number of spaces at the beginning."){|v| OPTIONS[:indent] = v.to_i}
op.parse!(ARGV)
OPTIONS[:time]   ||= ""
OPTIONS[:string] ||= ""
OPTIONS[:indent] ||= 0

WEEKDAYS = %w(Sun Mon Tue Wed Thu Fri Sat)
TODAY = DateTime.now

unless ARGV.size == 2
  puts "USAGE: dates from_date to_date"
  puts "  e.g., dates 2012-01-26 2012-02-29"
  puts "  e.g., dates 1-26 2-29"
  puts "  e.g., dates '' 29"
  puts "  e.g., dates 2012-01-26 2012-02-29 -t 12:30"
  puts "  e.g., dates 2012-01-26 2012-02-29 -s '@ string'"
  puts "  e.g., dates 2012-01-26 2012-02-29 -i 2"
  exit
end

def analyze_date(str)
  #pp TODAY
  nums = str.split(/[\-\/]/).map{|i| i.to_i}
  nums = [TODAY.day         ] if nums.size == 0
  nums = [TODAY.month, *nums] if nums.size == 1
  nums = [TODAY.year,  *nums] if nums.size == 2
  Date.new(* nums)
end
from_date = analyze_date(ARGV[0])
to_date   = analyze_date(ARGV[1])

if to_date < from_date
  puts "Error: from_date must be earlier than to_date"
  exit
end

#p from_date, to_date
current = from_date
while (current <= to_date)
  str = " " * OPTIONS[:indent]
  str += current.strftime("[%Y-%m-%d #{OPTIONS[:time]} (#{WEEKDAYS[current.wday]})]#{OPTIONS[:string]}").sub("  ", " ")
  puts str
  current += 1
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sculd-0.1.3 bin/dates
sculd-0.1.2 bin/dates
sculd-0.1.1 bin/dates
sculd-0.1.0 bin/dates
sculd-0.0.3 bin/dates