def test_new_timezone_wt_shift_backward(self): new_wt = Availability.new_timezone_wt(c.sunday_0000, c.et_ds, 'US/Arizona') self.assertEqual(new_wt, WeeklyTime(6, 21, 0)) new_wt = Availability.new_timezone_wt(c.tuesday_1715, c.kabul_2000_1_1, 'US/Samoa') self.assertEqual(new_wt, WeeklyTime(2, 1, 45)) new_wt = Availability.new_timezone_wt(c.thursday_0630, c.chatham_ds, 'Pacific/Midway') self.assertEqual(new_wt, WeeklyTime(3, 5, 45))
def test_new_timezone_wt_shift_forward(self): new_wt = Availability.new_timezone_wt(c.sunday_0000, c.et_ds, 'UTC') self.assertEqual(new_wt, WeeklyTime(0, 4, 0)) new_wt = Availability.new_timezone_wt(c.tuesday_1715, c.et_no_ds, 'Asia/Tokyo') self.assertEqual(new_wt, WeeklyTime(3, 7, 15)) new_wt = Availability.new_timezone_wt(c.saturday_2345, c.kathmandu_2017_end, 'Australia/West') self.assertEqual(new_wt, WeeklyTime(0, 2, 0))
def get_course_schedules(self): """ Computes the datetimes of the course schedule in the student's timezone, in the tutor's timezone, and in UTC. Returns: student_course_schedule: A list of datetimes of course start times localized to the student's timezone. tutor_course_schedule: A list of datetimes of course start times localized to the tutor's timezone. UTC_course_schedule: A list of datetimes of course start times localized to UTC. """ aware_UTC_start = pytz.utc.localize(self.earliest_course_start_UTC) earliest_course_start_student = aware_UTC_start.astimezone(self.student.tz) student_wt = Availability.new_timezone_wt(self.course_start_wt_UTC, aware_UTC_start, self.student.tz_str) student_first_course_dt = student_wt.first_datetime_after(earliest_course_start_student) student_course_schedule_naive = [student_first_course_dt + timedelta(days=Availability.DAYS_PER_WEEK*i) for i in range(self.weeks_per_course)] student_course_schedule = map(self.student.tz.localize, student_course_schedule_naive) tutor_course_schedule = [student_dt.astimezone(self.tutor.tz) for student_dt in student_course_schedule] UTC_course_schedule = [student_dt.astimezone(pytz.utc) for student_dt in student_course_schedule] return (student_course_schedule, tutor_course_schedule, UTC_course_schedule)
def test_new_timezone_wt_value_error(self): with self.assertRaises(ValueError): Availability.new_timezone_wt(WeeklyTime(0, 0, 14), c.utc_halloween, 'UTC') with self.assertRaises(ValueError): Availability.new_timezone_wt(WeeklyTime(0, 0, 0), c.dt_2000_1_1, 'UTC') with self.assertRaises(ValueError): Availability.new_timezone_wt(WeeklyTime(0, 0, 0), c.utc_halloween, 'utc')
def test_new_timezone_wt_same_tz(self): new_wt = Availability.new_timezone_wt(c.sunday_0000, c.utc_halloween, 'UTC') self.assertEqual(new_wt, c.sunday_0000)