Module: Arborist::TimeFunctions

Defined in:
lib/arborist/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.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/arborist/mixins.rb', line 113

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