Sha256: 49cee27a2701c9626b9de0811789bca3de87f62bfedf1b207bc7018f3139488e
Contents?: true
Size: 630 Bytes
Versions: 1
Compression:
Stored size: 630 Bytes
Contents
module Tabs module Resolutions module Week extend Tabs::Resolutionable extend self PATTERN = "%Y-%W" def serialize(timestamp) 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) self.normalize(dt) end def seconds(s) s / 1.week end def add(ts, num) ts + num.weeks end def normalize(ts) Time.utc(ts.year, ts.month, ts.day).beginning_of_week end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tabs-0.9.1 | lib/tabs/resolutions/week.rb |