lib/tabs/resolutions/week.rb in tabs-0.9.1 vs lib/tabs/resolutions/week.rb in tabs-1.0.0
- old
+ new
@@ -1,25 +1,31 @@
module Tabs
module Resolutions
module Week
- extend Tabs::Resolutionable
+ include Tabs::Resolutionable
extend self
- PATTERN = "%Y-%W"
+ PATTERN = "%Y-%m-%d"
+ def name
+ :week
+ end
+
def serialize(timestamp)
- timestamp.strftime(PATTERN)
+ normalize(timestamp).strftime(PATTERN)
end
def deserialize(str)
- year, week = str.split("-").map(&:to_i)
- week = 1 if week == 0
- dt = DateTime.strptime("#{year}-#{week}", PATTERN)
+ dt = DateTime.strptime(str, PATTERN)
self.normalize(dt)
end
- def seconds(s)
+ def from_seconds(s)
s / 1.week
+ end
+
+ def to_seconds
+ 1.week
end
def add(ts, num)
ts + num.weeks
end