rendered paste body#!/usr/bin/ruby
def countdown(fitem,fday)
fitems = fitem.split(":")
h = fitems[0].to_i
m = fitems[1].to_i
s = fitems[2].to_i
if fday.downcase =~ /sun/ then
$fdays = 1
elsif fday.downcase =~ /mon/ then
$fdays = 2
elsif fday.downcase =~ /tue/ then
$fdays = 3
elsif fday.downcase =~ /wed/ then
$fdays = 4
elsif fday.downcase =~ /thu/ then
$fdays = 5
elsif fday.downcase =~ /fri/ then
$fdays = 6
elsif fday.downcase =~ /sat/ then
$fdays = 7
end
t = Time.now.asctime.to_s
time = t.split(" ")
$days = 0
if time[0] == 'Sun' then
$days = 1
elsif time[0] == 'Mon' then
$days = 2
elsif time[0] == 'Tue' then
$days = 3
elsif time[0] == 'Wed' then
$days = 4
elsif time[0] == 'Thu' then
$days = 5
elsif time[0] == 'Fri' then
$days = 6
elsif time[0] == 'Sat' then
$days = 7
end
hms = time[3].split(":")
$hours = (hms[0].to_i - h) * -1
$mins = (hms[1].to_i - m) * -1
$secs = (hms[2].to_i - s) * -1
$eday = $fdays - $days
if $secs < 0 then
$secs = $secs + 60
$mins = $mins - 1
end
if $mins < 0 then
$mins = $mins + 60
$hours = $hours - 1
end
if $hours < 0 then
$hours = $hours + 24
$eday = $eday - 1
end
if $eday < 0 then
$eday = $eday + 7
end
if $hours > 1 || $hours == 0 then
$htxt = " hours, "
else
$htxt = " hour, "
end
if $mins > 1 || $mins == 0 then
$mtxt = " mins, "
else
$mtxt = " min, "
end
if $secs > 1 || $secs == 0 then
$stxt = " seconds "
else
$stxt = " second "
end
if $eday > 1 || $eday == 0 then
$dtxt = " days, "
else
$dtxt = " day, "
end
return $eday.to_s + $dtxt + $hours.to_s + $htxt + $mins.to_s + $mtxt + "and " + $secs.to_s + $stxt
end
puts countdown("19:00:00","Saturday") + "until Doctor Who" #change this for the time and date