Sha256: ec625588a8942e51137011a2e2c5016d4d928b96373c24a0678b0abd1d6aed31

Contents?: true

Size: 540 Bytes

Versions: 1

Compression:

Stored size: 540 Bytes

Contents

module Tabs
  module Resolutions
    module Hour
      extend Tabs::Resolutionable
      extend self

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

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

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

      def from_seconds(s)
        s / 1.hour
      end

      def add(ts, num)
        ts + num.hours
      end

      def normalize(ts)
        Time.utc(ts.year, ts.month, ts.day, ts.hour)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tabs-0.9.1 lib/tabs/resolutions/hour.rb