make todo_from_rich_message time zone aware. test was failing.

This commit is contained in:
Reinier Balt 2014-01-26 15:05:27 +01:00
parent 76b0ec024a
commit 63af3bbcfa
3 changed files with 10 additions and 6 deletions

View file

@ -51,12 +51,12 @@ class RichMessageExtractor
def due
due = select_for DUE_MARKER
due.blank? ? nil : Date.parse(due[1].strip)
due.blank? ? nil : Time.zone.parse(fix_date_string(due[1].strip))
end
def show_from
show_from = select_for TICKLER_MARKER
show_from.blank? ? nil : Date.parse(show_from[1].strip)
show_from.blank? ? nil : Time.zone.parse(fix_date_string(show_from[1].strip))
end
def starred?
@ -69,4 +69,8 @@ class RichMessageExtractor
@message.match /#{symbol}(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/
end
def fix_date_string yymmdd
"20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00"
end
end

View file

@ -48,8 +48,8 @@ class TodoFromRichMessage
todo.raw_notes = notes
todo.context_id = context_id
todo.project_id = project_id unless project_id.nil?
todo.show_from = show_from if show_from.is_a? Date
todo.due = due if due.is_a? Date
todo.show_from = show_from if show_from.is_a? Time
todo.due = due if due.is_a? Time
todo.tag_with tags unless tags.nil? || tags.empty?
todo.starred = star
todo

View file

@ -31,8 +31,8 @@ class TodoFromRichMessageTest < ActiveSupport::TestCase
assert_equal "notes", new_todo.notes
assert_equal context.id, new_todo.context_id
assert_equal project.id, new_todo.project_id
assert_equal "2013-10-14 00:00:00 +0100", new_todo.show_from.to_s
assert_equal "2013-10-17 00:00:00 +0100", new_todo.due.to_s
assert_equal Time.zone.parse("2013-10-14 00:00"). utc.to_s, new_todo.show_from.utc.to_s
assert_equal Time.zone.parse("2013-10-17 00:00"), new_todo.due.utc.to_s
assert_equal "starred, tag1, tag2", new_todo.tags.to_s
assert new_todo.starred?
end