Module: Toy::Extensions::Date

Included in:
Date
Defined in:
lib/toy/extensions/date.rb

Instance Method Summary collapse

Instance Method Details

#from_store(value) ⇒ Object



15
16
17
# File 'lib/toy/extensions/date.rb', line 15

def from_store(value, *)
  value.to_date if value.present?
end

#to_store(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/toy/extensions/date.rb', line 4

def to_store(value, *)
  if value.nil? || value == ''
    nil
  else
    date = value.is_a?(::Date) || value.is_a?(::Time) ? value : ::Date.parse(value.to_s)
    ::Time.utc(date.year, date.month, date.day)
  end
rescue
  nil
end