1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

synchronized with date2 3.6.1

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2004-09-25 23:10:36 +00:00
parent 7e827e6694
commit c26e86fd1b
3 changed files with 81 additions and 32 deletions

View file

@ -1,7 +1,7 @@
#! /usr/bin/env ruby
# cal.rb: Written by Tadayoshi Funaba 1998-2004
# $Id: cal.rb,v 2.7 2004-01-10 23:52:51+09 tadf Exp $
# $Id: cal.rb,v 2.8 2004-09-25 12:50:10+09 tadf Exp $
require 'date'
@ -121,17 +121,36 @@ end
if __FILE__ == $0
require 'getopts'
require 'getoptlong'
def usage
warn 'usage: cal [-c iso3166] [-jmty] [[month] year]'
exit 1
end
usage unless getopts('jmty', "c:#{Cal::DEFAULT_START}")
cal = Cal.new
begin
GetoptLong.new(['-c', GetoptLong::REQUIRED_ARGUMENT],
['-j', GetoptLong::NO_ARGUMENT],
['-m', GetoptLong::NO_ARGUMENT],
['-t', GetoptLong::NO_ARGUMENT],
['-y', GetoptLong::NO_ARGUMENT]).
each do |opt, arg|
case opt
when '-c'; cal.opt_c(arg) || raise
when '-j'; cal.opt_j(true)
when '-m'; cal.opt_m(true)
when '-t'; cal.opt_t(true)
when '-y'; cal.opt_y(true)
end
end
rescue
usage
end
y, m = ARGV.values_at(1, 0).compact.collect{|x| x.to_i}
$OPT_y ||= (y and not m)
cal.opt_y(true) if y and not m
to = Date.today
y ||= to.year
@ -139,15 +158,6 @@ if __FILE__ == $0
usage unless m >= 1 and m <= 12
usage unless y >= -4712
usage if Cal::START[$OPT_c].nil?
cal = Cal.new
cal.opt_j($OPT_j)
cal.opt_m($OPT_m)
cal.opt_t($OPT_t)
cal.opt_y($OPT_y)
cal.opt_c($OPT_c)
print cal.print(y, m)