# # parsedate2.rb # written by Shin'ya Adzumi/ICHIGO-DENPA-CLUB # require 'parsedate' require 'timezone' module ParseDate def to_t(str,*base) basetime,basezone = [nil,nil] for b in base if( b.kind_of?(Time) ) then if( basetime.nil? ) then basetime = b else raise TypeError,"wrong argument type #{b.inspect}" end end if( b.kind_of?(String) ) then if( basezone.nil? ) then basezone = b else raise TypeError,"wrong argument type #{b.inspect}" end end end basetime = Time::now.gmtime if basetime.nil? basezone = Time::local(0).zone if basezone.nil? d = parsedate(str) raise ArgumentError,'invalid string' if( d[1].nil? ) d[0] = basetime.year if( d[0].nil? ) d[6] = basezone if( d[6].nil? ) Time::gm(d[0],d[1],d[2],d[3],d[4],d[5]) - TimeZone::to_s(d[6]) end module_function :to_t end if __FILE__ == $0 then p ParseDate::to_t ARGV[0],Time::now.gmtime,"JST" end