#!/usr/bin/ruby # '7/1 1:20' $h = $m = $s = $j = $mm = $a = nil def try_hour(s) case s when /^(\d+):(\d+):(\d+)$/ $h, $m, $s = $1.to_i, $2.to_i, $3.to_i when /^(\d+)[:h](\d+)$/ $h, $m, $s = $1.to_i, $2.to_i, 0 when /^(\d+)h$/ $h, $m, $s = $1.to_i, 0, 0 end end def try_date(s) case s when /^(\d+)\/(\d+)\/(\d+)$/ $j, $mm, $a = $1.to_i, $2.to_i, $3.to_i when /^(\d+)\/(\d+)$/ $j, $mm, $a = $1.to_i, $2.to_i, Time.now.year when /^(\d+)$/ $j, $mm, $a = $1.to_i, Time.now.month, Time.now.year end end if try_date(ARGV[0]) try_hour(ARGV[1]) else try_date(ARGV[1]) try_hour(ARGV[0]) end raise "invalid date" unless $h if not $j $j, $mm, $a = Time.now.day, Time.now.month, Time.now.year wakedate = Time.mktime($a, $mm, $j, $h, $m, $s) if wakedate < Time.now wakedate += 24*3600 end else wakedate = Time.mktime($a, $mm, $j, $h, $m, $s) end delay = wakedate.to_i - Time.now.to_i puts "sleeping #{delay/3600}h#{delay/60%60} til #{wakedate.strftime('%d/%m %H:%M')}" sleep delay