Last active
August 29, 2015 14:12
-
-
Save mattsan/b349fbce6af0b0df40b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# coding: utf-8 | |
require 'date' | |
begin | |
raise unless ARGV.size == 3 | |
date_range = ARGV.shift.match(/(\d{1,2}\/\d{1,2})-(\d{1,2}\/\d{1,2})/) { Date.parse($1)..Date.parse($2) } | |
start_time, end_time = ARGV.shift.match(/(\d{1,2}\:\d{1,2})-(\d{1,2}\:\d{1,2})/) { [DateTime.parse($1), DateTime.parse($2)] } | |
step = ARGV.shift.to_f | |
raise unless date_range && start_time && end_time && step > 0 | |
rescue | |
puts 'mm/dd-mm/dd hh:mm-hh:mm h 形式で日時を入力' | |
exit 1 | |
end | |
WDAYS = '日月火水木金土' | |
times = start_time.step(end_time, step/24.0).each_cons(2).with_object([]) do |(stime, etime), arr| | |
arr << "#{stime.strftime('%H:%M')}-#{etime.strftime('%H:%M')}" | |
end | |
date_range.to_a.product(times).each do |date, time| | |
puts "#{date.strftime('%m/%d')}(#{WDAYS[date.wday]}) #{time}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment