Sha256: c8adb497452b4f11e622da861a455651f4fcaa6a61c27152d1d73fcbb5a035a1
Contents?: true
Size: 931 Bytes
Versions: 1
Compression:
Stored size: 931 Bytes
Contents
module TimeScopes class << self 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 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 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 def overall(start=nil) [ Chronic.parse('2000-01-01 00:00:00'), Chronic.parse(start_of_day(1.day.from_now.utc)) ] end def start_of_day(time) time.strftime("%Y-%m-%d 00:00:00Z") end def start_of_month(time) time.strftime("%Y-%m-01 00:00:00Z") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timescopes-0.1.0 | lib/timescopes.rb |