Module: Tabs::Resolutions::Month

Extended by:
Month
Includes:
Tabs::Resolutionable
Included in:
Month
Defined in:
lib/tabs/resolutions/month.rb

Constant Summary collapse

PATTERN =
"%Y-%m"

Instance Method Summary collapse

Methods included from Tabs::Resolutionable

#expire, included

Instance Method Details

#add(ts, num) ⇒ Object



30
31
32
# File 'lib/tabs/resolutions/month.rb', line 30

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

#deserialize(str) ⇒ Object



17
18
19
20
# File 'lib/tabs/resolutions/month.rb', line 17

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

#from_seconds(s) ⇒ Object



22
23
24
# File 'lib/tabs/resolutions/month.rb', line 22

def from_seconds(s)
  s / 1.month
end

#nameObject



9
10
11
# File 'lib/tabs/resolutions/month.rb', line 9

def name
  :month
end

#normalize(ts) ⇒ Object



34
35
36
# File 'lib/tabs/resolutions/month.rb', line 34

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

#serialize(timestamp) ⇒ Object



13
14
15
# File 'lib/tabs/resolutions/month.rb', line 13

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

#to_secondsObject



26
27
28
# File 'lib/tabs/resolutions/month.rb', line 26

def to_seconds
  1.month
end