Sha256: 7c6f12b60b6e10ff60177454a4630987f1a631ee1288bf27d81b4199b5b03bee

Contents?: true

Size: 950 Bytes

Versions: 1

Compression:

Stored size: 950 Bytes

Contents

require 'chronic'

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.1 lib/timescopes/scopes.rb