Skip to content

Commit

Permalink
Make #to_formatted_s handle nils in datetime_value. NUBIC#459.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Yip committed Jun 21, 2013
1 parent 22a3d5a commit a37c4e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/surveyor/models/response_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def correct?
end

def time_value
read_attribute(:datetime_value).strftime( time_format ) unless read_attribute(:datetime_value).blank?
datetime_value.try(:strftime, time_format)
end

def time_value=(val)
Expand All @@ -64,7 +64,7 @@ def time_value=(val)
end

def date_value
read_attribute(:datetime_value).strftime( date_format ) unless read_attribute(:datetime_value).blank?
datetime_value.try(:strftime, date_format)
end

def date_value=(val)
Expand All @@ -76,6 +76,10 @@ def date_value=(val)
end
end

def datetime_value
read_attribute(:datetime_value)
end

def time_format
'%H:%M'
end
Expand All @@ -98,7 +102,7 @@ def to_formatted_s
when :time
time_value
when :datetime
read_attribute(:datetime_value).strftime(datetime_format)
datetime_value.try(:strftime, datetime_format) || ''
else
to_s
end
Expand Down

0 comments on commit a37c4e1

Please sign in to comment.