Class: Ptimelog::NamedDate

Inherits:
Object
  • Object
show all
Defined in:
lib/ptimelog/named_date.rb

Overview

Mapping between semantic/relative names and absolute dates

Instance Method Summary collapse

Instance Method Details

#date(arg = 'last') ⇒ Object



8
9
10
# File 'lib/ptimelog/named_date.rb', line 8

def date(arg = 'last')
  named_date(arg) || :all
end

#named_date(date) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ptimelog/named_date.rb', line 12

def named_date(date)
  case date.to_s
  when 'yesterday'        then Date.today.prev_day.to_s
  when 'today'            then Date.today.to_s
  when 'last', ''         then timelog.to_h.keys.compact.sort[-2] || Date.today.prev_day.to_s
  when /\d{4}(-\d{2}){2}/ then date
  end
end