Sha256: 4e7b820dd64934a46e1a5d699e866888636b1d06e0cd64932e65ab283ece1574

Contents?: true

Size: 488 Bytes

Versions: 6

Compression:

Stored size: 488 Bytes

Contents

module Tabs
  module Resolutions
    module Week
      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 normalize(ts)
        Time.utc(ts.year, ts.month, ts.day).beginning_of_week
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tabs-0.5.6 lib/tabs/resolutions/week.rb
tabs-0.5.5 lib/tabs/resolutions/week.rb
tabs-0.5.4 lib/tabs/resolutions/week.rb
tabs-0.5.3 lib/tabs/resolutions/week.rb
tabs-0.5.2 lib/tabs/resolutions/week.rb
tabs-0.5.0 lib/tabs/resolutions/week.rb