Permalink
Browse files

CLC-916 Do not unintentionally cross end-of-week when time-shifting

  • Loading branch information...
1 parent 8dd022c commit 93ccf1d592b054807ea64b9f9635b3580ab22940 @raydavis raydavis committed Dec 21, 2012
Showing with 20 additions and 14 deletions.
  1. +6 −2 config/initializers/timeshift.rb
  2. +12 −12 fixtures/pretty_vcr_recordings/Google_tasks.json
  3. +2 −0 spec/models/my_tasks_spec.rb
@@ -6,21 +6,25 @@
# midnight on the current day
today = Date.today.to_time_in_current_zone.to_datetime
+ # Google tasks store due dates as zero-hour Z-time
+ end_of_week_utc = today.sunday.to_date.to_datetime
+ next_week_utc = end_of_week_utc.advance(days: 2)
+
substitutions = {
":::TWENTY_SEVEN_DAYS_AGO:::" => today.advance(:days => -27).rfc3339,
":::TWO_DAYS_AGO_MIDNIGHT_PST:::" => today.advance(:days => -1, :minutes => -1).rfc3339,
":::TODAY_MIDNIGHT_PST:::" => today.rfc3339,
":::TOMORROW_MIDNIGHT_PST:::" => today.advance(:days => 1).rfc3339,
":::TODAY_AT_TEA_TIME:::" => today.advance(:hours => 15, :minutes => 47, :seconds => 13).rfc3339,
- ":::TWO_DAYS_HENCE:::" => today.advance(:days => 2).rfc3339,
- ":::THREE_DAYS_HENCE:::" => today.advance(:days => 3).rfc3339,
":::SIX_DAYS_HENCE:::" => today.advance(:days => 6).rfc3339,
":::TODAY_NINE:::" => today.advance(:hours => 9, :minutes => 00, :seconds => 00).rfc3339,
":::TODAY_TEN:::" => today.advance(:hours => 10, :minutes => 00, :seconds => 00).rfc3339,
":::TODAY_LUNCHTIME:::" => today.advance(:hours => 12, :minutes => 30, :seconds => 00).rfc3339,
":::TODAY_AFTER_LUNCH:::" => today.advance(:hours => 14, :minutes => 00, :seconds => 00).rfc3339,
":::TODAY_THREE_THIRTY:::" => today.advance(:hours => 15, :minutes => 30, :seconds => 00).rfc3339,
":::TODAY_FOUR_THIRTY:::" => today.advance(:hours => 16, :minutes => 30, :seconds => 00).rfc3339,
+ ":::UTC_LATER_IN_WEEK:::" => end_of_week_utc.rfc3339(3),
+ ":::UTC_NEXT_WEEK:::" => next_week_utc.rfc3339(3),
}
Rails.logger.info "Timeshifter: Today = #{today}; epoch = #{today.to_i}"
@@ -84,7 +84,7 @@
"position": "00000000000033554431",
"notes": "Turn in your teaching evaluation for Math 53",
"status": "needsAction",
- "due": ":::TWO_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -95,7 +95,7 @@
"selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDoxNTQ3MjA3ODkz",
"position": "00000000000134217727",
"status": "needsAction",
- "due": ":::THREE_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -106,7 +106,7 @@
"selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDo2OTQ1MjI2Nzk",
"position": "00000000000268435455",
"status": "needsAction",
- "due": ":::THREE_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -139,7 +139,7 @@
"position": "00000000002147483647",
"notes": "Submit a signed Emergency Loan promissory note",
"status": "needsAction",
- "due": ":::SIX_DAYS_HENCE:::"
+ "due": ":::UTC_NEXT_WEEK:::"
}
]
}
@@ -234,7 +234,7 @@
"position":"00000000000033554431",
"notes":"Turn in your teaching evaluation for Math 53",
"status":"needsAction",
- "due":":::TWO_DAYS_HENCE:::"
+ "due":":::UTC_LATER_IN_WEEK:::"
},
{
"kind":"tasks#task",
@@ -245,7 +245,7 @@
"selfLink":"https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDoxNTQ3MjA3ODkz",
"position":"00000000000134217727",
"status":"needsAction",
- "due":":::THREE_DAYS_HENCE:::"
+ "due":":::UTC_LATER_IN_WEEK:::"
},
{
"kind":"tasks#task",
@@ -256,7 +256,7 @@
"selfLink":"https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDo2OTQ1MjI2Nzk",
"position":"00000000000268435455",
"status":"needsAction",
- "due":":::THREE_DAYS_HENCE:::"
+ "due":":::UTC_LATER_IN_WEEK:::"
},
{
"kind":"tasks#task",
@@ -289,7 +289,7 @@
"position":"00000000002147483647",
"notes":"Submit a signed Emergency Loan promissory note",
"status":"needsAction",
- "due":":::SIX_DAYS_HENCE:::"
+ "due":":::UTC_NEXT_WEEK:::"
}
]
}
@@ -381,7 +381,7 @@
"position": "00000000000033554431",
"notes": "Turn in your teaching evaluation for Math 53",
"status": "needsAction",
- "due": ":::TWO_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -392,7 +392,7 @@
"selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDoxNTQ3MjA3ODkz",
"position": "00000000000134217727",
"status": "needsAction",
- "due": ":::THREE_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -403,7 +403,7 @@
"selfLink": "https://www.googleapis.com/tasks/v1/lists/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDow/tasks/MDM3NDMyMTM2NzUwNzM1MDg0MTc6MDo2OTQ1MjI2Nzk",
"position": "00000000000268435455",
"status": "needsAction",
- "due": ":::THREE_DAYS_HENCE:::"
+ "due": ":::UTC_LATER_IN_WEEK:::"
},
{
"kind": "tasks#task",
@@ -436,7 +436,7 @@
"position": "00000000002147483647",
"notes": "Submit a signed Emergency Loan promissory note",
"status": "needsAction",
- "due": ":::SIX_DAYS_HENCE:::"
+ "due": ":::UTC_NEXT_WEEK:::"
}
]
}
@@ -62,6 +62,8 @@
end
overdue_counter.should == 0
+ # On Sundays, this test will fail because no "Due This Week" tasks will escape
+ # the "Due Today" bucket.
today_counter.should == 0
this_week_counter.should == 0
next_week_counter.should == 0

0 comments on commit 93ccf1d

Please sign in to comment.