From 63af3bbcfad507dfb028a113f209755391540e07 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Sun, 26 Jan 2014 15:05:27 +0100 Subject: [PATCH] make todo_from_rich_message time zone aware. test was failing. --- app/services/rich_message_extractor.rb | 8 ++++++-- app/services/todo_from_rich_message.rb | 4 ++-- test/models/todo_from_rich_message_test.rb | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/services/rich_message_extractor.rb b/app/services/rich_message_extractor.rb index e248ad1e..9b19a855 100644 --- a/app/services/rich_message_extractor.rb +++ b/app/services/rich_message_extractor.rb @@ -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 diff --git a/app/services/todo_from_rich_message.rb b/app/services/todo_from_rich_message.rb index b1a28f22..bf567797 100644 --- a/app/services/todo_from_rich_message.rb +++ b/app/services/todo_from_rich_message.rb @@ -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 diff --git a/test/models/todo_from_rich_message_test.rb b/test/models/todo_from_rich_message_test.rb index 2b57da38..01d9fbb6 100644 --- a/test/models/todo_from_rich_message_test.rb +++ b/test/models/todo_from_rich_message_test.rb @@ -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