Module: TimeScopes

Defined in:
lib/timescopes/scopes.rb,
lib/timescopes/rails/active_record_extension.rb

Defined Under Namespace

Modules: Rails

Class Method Summary collapse

Class Method Details

.daily(start = nil) ⇒ Object



17
18
19
20
21
# File 'lib/timescopes/scopes.rb', line 17

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

.hourly(start = nil) ⇒ Object



11
12
13
14
15
# File 'lib/timescopes/scopes.rb', line 11

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

.minutely(start = nil) ⇒ Object



5
6
7
8
9
# File 'lib/timescopes/scopes.rb', line 5

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

.monthly(start = nil) ⇒ Object



31
32
33
34
35
# File 'lib/timescopes/scopes.rb', line 31

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

.overall(start = nil) ⇒ Object



37
38
39
40
# File 'lib/timescopes/scopes.rb', line 37

def overall(start=nil)
  [ Chronic.parse('2000-01-01 00:00:00'),
    Chronic.parse(start_of_day(1.day.from_now.utc)) ]
end

.start_of_day(time) ⇒ Object



50
51
52
# File 'lib/timescopes/scopes.rb', line 50

def start_of_day(time)
  time.strftime("%Y-%m-%d 00:00:00Z")
end

.start_of_hour(time) ⇒ Object



46
47
48
# File 'lib/timescopes/scopes.rb', line 46

def start_of_hour(time)
  time.strftime("%Y-%m-%d %H:00:00Z")
end

.start_of_minute(time) ⇒ Object



42
43
44
# File 'lib/timescopes/scopes.rb', line 42

def start_of_minute(time)
  time.strftime("%Y-%m-%d %H:%M:00Z")
end

.start_of_month(time) ⇒ Object



54
55
56
# File 'lib/timescopes/scopes.rb', line 54

def start_of_month(time)
  time.strftime("%Y-%m-01 00:00:00Z")
end

.weekly(start = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/timescopes/scopes.rb', line 23

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