Sha256: 8169773ca78642050337689b4bd1b4a18bce273f1fa49c85141b0671d95fa829

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

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

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

      def name
        :minute
      end

      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.minute
      end

      def to_seconds
        1.minute
      end

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

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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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