def test_compute_end_time_from_text(self): start_time = dt() computed = utils.compute_end_time(" 15 minutes ", start_time) self.assertEqual(dt(minute=16), computed) computed = utils.compute_end_time(" 15 hours 12 minutes ", start_time) self.assertEqual(dt(hour=16, minute=13), computed)
def test_compute_end_time_from_hour_ordinal(self): start_time = dt() computed = utils.compute_end_time(" 4:57 AM ", start_time) self.assertEqual(dt(hour=4, minute=57), computed) computed = utils.compute_end_time(" 04:57 AM ", start_time) self.assertEqual(dt(hour=4, minute=57), computed) start_time = dt(hour=13, minute=1) computed = utils.compute_end_time(" 04:57 PM ", start_time) self.assertEqual(dt(hour=16, minute=57), computed)
def POST(self, client_id, entry_id=None): entry = get_one("time_entries", entry_id) f = self.form(client_id) if f.validates(): date_str = "{} {}".format(f.d.start_date.strip(), f.d.start_time.strip()) start_time = end_time = datetime.strptime(date_str, "%m/%d/%Y %I:%M %p") end_time = utils.compute_end_time(f.d.duration, start_time) if entry: db.update("time_entries", where="id=$entry_id", vars={'entry_id': entry_id}, description=f.d.description, start_time=start_time, end_time=end_time, category_id=f.d.category_id) else: db.insert("time_entries", client_id=client_id, description=f.d.description, start_time=start_time, end_time=end_time, category_id=f.d.category_id) raise web.seeother("/clients/%s/entries/" % client_id) else: return render.form(f)
def test_compute_end_time_empty(self): computed = utils.compute_end_time(None, None) self.assertEqual(None, computed) computed = utils.compute_end_time(" ", None) self.assertEqual(None, computed)
def test_compute_end_time_from_duration(self): start_time = dt() computed = utils.compute_end_time(" 15 ", start_time) self.assertEqual(dt(minute=16), computed)