Sha256: 67e1c60f90c2b4451779b17671645fdf1630452dead7c6f88158cb0ca780a1e2

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module CountdownTimer
  class Timer
    class << self
      def set_timer(year, month = 1, day = 1, hour = 0, min = 0, sec = 0)
        now = Time.now.to_i
        destination_time = Time.new(year, month, day, hour, min, sec).to_i
        remaining_day = 0

        if now > destination_time
          total_secs = now - destination_time
          total_hours = total_secs / 60 / 60
          remaining_day = total_hours / 24 if total_hours > 24
          remaining_hour = total_hours - (remaining_day * 24)
          remaining_min = total_secs / 60 % 60
          remaining_sec = total_secs - ((remaining_day * 24 * 60 * 60) + (remaining_hour * 60 * 60) + (remaining_min * 60))
        else
          total_secs = destination_time - now
          total_hours = total_secs / 60 / 60
          remaining_day = total_hours / 24 if total_hours > 24
          remaining_hour = total_hours - (remaining_day * 24)
          remaining_min = total_secs / 60 % 60
          remaining_sec = total_secs - ((remaining_day * 24 * 60 * 60) + (remaining_hour * 60 * 60) + (remaining_min * 60))
        end

        return "#{remaining_day}/#{remaining_hour}:#{remaining_min}:#{remaining_sec}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
countdown_timer-0.1.1 lib/countdown_timer/timer.rb