Module: Schedulability::TimeFunctions

Defined in:
lib/schedulability/mixins.rb

Overview

Functions for time calculations

Class Method Summary collapse

Class Method Details

.calculate_seconds(count, unit) ⇒ Object

Calculate the (approximate) number of seconds that are in count of the given unit of time.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/schedulability/mixins.rb', line 18

def calculate_seconds( count, unit )
	return case unit
	when :seconds, :second
		count
	when :minutes, :minute
		count * 60
	when :hours, :hour
		count * 3600
	when :days, :day
		count * 86400
	when :weeks, :week
		count * 604800
	when :fortnights, :fortnight
		count * 1209600
	when :months, :month
		count * 2592000
	when :years, :year
		count * 31557600
	else
		raise ArgumentError, "don't know how to calculate seconds in a %p" % [ unit ]
	end
end