lib/abaci/date_range.rb in abaci-0.2.0 vs lib/abaci/date_range.rb in abaci-0.3.0
- old
+ new
@@ -1,7 +1,10 @@
module Abaci
+ require "active_support/core_ext/time"
+
class DateRange
+
attr_reader :start, :finish
def initialize(start, finish)
if start < finish
@start = start
@@ -15,27 +18,32 @@
def days
range.to_a
end
def keys
- days.map { |d| d.strftime('%Y:%-m:%-d') }
+ days.map { |d| d.strftime("%Y:%-m:%-d") }
end
def range
start..finish
end
def self.ago(days = 30)
seconds = days.to_i * 86400
- start = (Date.today - Rational(seconds, 86400)).to_date
- new(start, Date.today)
+ start = (now.to_date - Rational(seconds, 86400)).to_date
+ new(start, now.to_date)
end
def self.between(start, finish)
new(start, finish)
end
+ def self.now
+ Time.now.in_time_zone(Abaci.time_zone)
+ end
+
def self.since(date)
- new(date, Date.today)
+ new(date, now.to_date)
end
+
end
-end
\ No newline at end of file
+end