module TimeScopes

Public Class Methods

alltime(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 72
def alltime(start=nil)
  [ Chronic.parse('1970-01-01 00:00:00Z'),
    Chronic.parse(start_of_day(1.day.from_now.utc)) ]
end
daily(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 42
def daily(start=nil)
  start ||= Time.now
  [ Chronic.parse(start_of_day(start.utc)),
    Chronic.parse(start_of_day(1.day.since(start.utc))) ]
end
Also aliased as: day
day(start=nil)
Alias for: daily
hour(start=nil)
Alias for: hourly
hourly(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 35
def hourly(start=nil)
  start ||= Time.now
  [ Chronic.parse(start_of_hour(start.utc)),
    Chronic.parse(start_of_hour(1.hour.since(start.utc))) ]
end
Also aliased as: hour
minute(start=nil)
Alias for: minutely
minutely(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 28
def minutely(start=nil)
  start ||= Time.now
  [ Chronic.parse(start_of_minute(start.utc)),
    Chronic.parse(start_of_minute(1.minute.since(start.utc))) ]
end
Also aliased as: minute
month(start=nil)
Alias for: monthly
monthly(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 58
def monthly(start=nil)
  start ||= Time.now
  [ Chronic.parse(start_of_month(start.utc)),
    Chronic.parse(start_of_month(1.month.since(start.utc))) ]
end
Also aliased as: month
next_range(scope, start) click to toggle source
# File lib/timescopes/scopes.rb, line 5
def next_range(scope, start)
  case scope.to_sym
  when :minutely, :minute
    1.hour.since(start).utc
  when :hourly, :hour
    1.day.since(start).utc
  when :daily, :day
    1.day.since(start).utc
  when :weekly, :week
    1.week.since(start).utc
  when :monthly, :month
    1.month.since(start).utc
  when :yearly, :year
    1.year.since(start).utc
  when :rolling_7, :rolling_30
    1.day.since(start).utc
  when :total, :overall, nil
    nil
  else
    raise "Unknown scope passed to TimeScopes.next_range"
  end
end
start_of_day(time) click to toggle source
# File lib/timescopes/scopes.rb, line 85
def start_of_day(time)
  time.strftime("%Y-%m-%d 00:00:00Z")
end
start_of_hour(time) click to toggle source
# File lib/timescopes/scopes.rb, line 81
def start_of_hour(time)
  time.strftime("%Y-%m-%d %H:00:00Z")
end
start_of_minute(time) click to toggle source
# File lib/timescopes/scopes.rb, line 77
def start_of_minute(time)
  time.strftime("%Y-%m-%d %H:%M:00Z")
end
start_of_month(time) click to toggle source
# File lib/timescopes/scopes.rb, line 89
def start_of_month(time)
  time.strftime("%Y-%m-01 00:00:00Z")
end
start_of_year(time) click to toggle source
# File lib/timescopes/scopes.rb, line 93
def start_of_year(time)
  time.strftime("%Y-01-01 00:00:00Z")
end
week(start=nil)
Alias for: weekly
weekly(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 49
def weekly(start=nil)
  start ||= Time.now
  start = start.utc
  start = start - 1.day while !start.monday?
  [ Chronic.parse(start_of_day(start.utc)),
    Chronic.parse(start_of_day(1.week.since(start.utc))) ]
end
Also aliased as: week
year(start=nil)
Alias for: yearly
yearly(start=nil) click to toggle source
# File lib/timescopes/scopes.rb, line 65
def yearly(start=nil)
  start ||= Time.now
  [ Chronic.parse(start_of_year(start.utc)),
    Chronic.parse(start_of_year(1.year.since(start.utc))) ]
end
Also aliased as: year