Permalink
Browse files

fixes on element on edge case of day_after_tomorrow, not so wonderful…

… fudging of google task dates
  • Loading branch information...
1 parent 6478bb5 commit 88478ab537ec280f390177c70d8a755d1658f302 @yuhunglin yuhunglin committed Dec 5, 2012
Showing with 7 additions and 5 deletions.
  1. +5 −3 app/models/my_tasks.rb
  2. +2 −2 spec/models/my_tasks_spec.rb
View
@@ -102,7 +102,8 @@ def fetch_canvas_tasks
def convert_due_date(due_date, formatted_entry)
if !due_date.blank?
- due = DateTime.parse(due_date.to_s).in_time_zone
+ due = due_date.to_time_in_current_zone.to_datetime if due_date.is_a?(Date)
+ due ||= DateTime.parse(due_date.to_s)
formatted_entry["due_date"] = {
"epoch" => due.to_i,
"datetime" => due.rfc3339(3),
@@ -115,7 +116,8 @@ def convert_due_date(due_date, formatted_entry)
def determine_bucket(due_date, status, formatted_entry)
bucket = "unscheduled"
if !due_date.blank?
- due = DateTime.parse(due_date.to_s).in_time_zone
+ due = due_date.to_time_in_current_zone if due_date.is_a?(Date)
+ due ||= DateTime.parse(due_date.to_s)
@starting_date = @starting_date.to_time.in_time_zone.to_i unless @starting_date.is_a?(Time)
today = @starting_date.to_i
tomorrow = @starting_date.advance(:days => 1).to_i
@@ -126,7 +128,7 @@ def determine_bucket(due_date, status, formatted_entry)
formatted_entry["status"] = "overdue" if (status == "needs_action" && (due.to_i < today))
elsif due.to_i >= tomorrow && due.to_i < day_after_tomorrow
bucket = "due_tomorrow"
- elsif due.to_i > day_after_tomorrow
+ elsif due.to_i >= day_after_tomorrow
bucket = "upcoming"
end
@@ -19,9 +19,9 @@
valid_feed["sections"][0]["title"].should == "Due"
valid_feed["sections"][0]["tasks"].size.should == 3
valid_feed["sections"][1]["title"].should == "Due Tomorrow"
- valid_feed["sections"][1]["tasks"].size.should == 1
+ valid_feed["sections"][1]["tasks"].size.should == 0
valid_feed["sections"][2]["title"].should == "Upcoming"
- valid_feed["sections"][2]["tasks"].size.should == 3
+ valid_feed["sections"][2]["tasks"].size.should == 4
valid_feed["sections"][3]["title"].should == "Unscheduled"
valid_feed["sections"][3]["tasks"].size.should == 1
valid_feed["sections"].each do |section|

0 comments on commit 88478ab

Please sign in to comment.