Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/octocore-cassandra/utils.rb

Instance Method Summary collapse

Instance Method Details

#ceil(height = 1) ⇒ Object

Find ceil time

Parameters:

  • height (Fixnum) (defaults to: 1)

    The minutes of height for ceil. Defaults to 1



39
40
41
42
43
44
45
# File 'lib/octocore-cassandra/utils.rb', line 39

def ceil(height = 1)
  if height < 1
    height = 1
  end
  sec = height.to_i * 60
  Time.at((1 + (self.to_i / sec)).round * sec)
end

#floor(height = 1) ⇒ Object

Find floor time

Parameters:

  • height (Fixnum) (defaults to: 1)

    The minutes of height for floor. Defaults to 1



29
30
31
32
33
34
35
# File 'lib/octocore-cassandra/utils.rb', line 29

def floor(height = 1)
  if height < 1
    height = 1
  end
  sec = height.to_i * 60
  Time.at((self.to_i / sec).round * sec)
end

#to(to, step = 15.minutes) ⇒ Array<Time>

Finds the steps between two time.

Parameters:

  • to (Time)

    The end time

  • step (Time) (defaults to: 15.minutes)

    The step time. Defaults to 15.minute

Returns:

  • (Array<Time>)

    An array containint times



51
52
53
# File 'lib/octocore-cassandra/utils.rb', line 51

def to(to, step = 15.minutes)
  [self].tap { |array| array << array.last + step while array.last < to }
end