Sha256: d23fed326c060b2a36616e7bbb9d194f5b1352abace3e7e596e9fe446ac83712

Contents?: true

Size: 645 Bytes

Versions: 2

Compression:

Stored size: 645 Bytes

Contents

module Tabs
  module Resolutions
    module Week
      include Tabs::Resolutionable
      extend self

      PATTERN = "%Y-%m-%d"

      def name
        :week
      end

      def serialize(timestamp)
        normalize(timestamp).strftime(PATTERN)
      end

      def deserialize(str)
        dt = DateTime.strptime(str, PATTERN)
        self.normalize(dt)
      end

      def from_seconds(s)
        s / 1.week
      end

      def to_seconds
        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

2 entries across 2 versions & 1 rubygems

Version Path
tabs-1.0.1 lib/tabs/resolutions/week.rb
tabs-1.0.0 lib/tabs/resolutions/week.rb