Exemple #1
0
    def test_add(self):
        start_time = WdcTime("0800")
        end_time = WdcTime("0030")

        sum_time = start_time + end_time

        self.assertEqual("08", sum_time.hours)
        self.assertEqual("30", sum_time.minutes)
Exemple #2
0
def calc_workday_end(start_time: str, break_duration: int,
                     workday_duration: str):
    start = WdcTime(start_time)
    duration = WdcTime(workday_duration)

    result = start + duration
    result.add_minutes(break_duration)

    return result
Exemple #3
0
def task_to_printout(task: WdcTask) -> List[str]:
    start = WdcTime(task.start)
    if task.end != '':
        end = WdcTime(task.end)

    return [
        task.id, task.date, f'{start.hours}:{start.minutes}',
        f'{end.hours}:{end.minutes}' if task.end != '' else task.end,
        task.tags, (task.description[:10] +
                    '..') if task.description != '' else task.description
    ]
Exemple #4
0
    def test_init(self):
        # Upper out of bounds
        self.assertRaises(ValueError, WdcTime, "2360")

        # maximal numer of minutes is 59 so this time is invalid
        self.assertRaises(ValueError, WdcTime, "1260")

        # min valid time value
        self.assertTrue(WdcTime("0000"))

        # maximal valid time value
        self.assertTrue(WdcTime("2359"))
Exemple #5
0
    def test_compare(self):
        small_time = WdcTime('0800')
        big_time = WdcTime('0900')

        self.assertTrue(small_time < big_time)
        self.assertFalse(small_time < small_time)
        self.assertTrue(small_time <= small_time)
        self.assertFalse(big_time < small_time)

        self.assertTrue(big_time > small_time)
        self.assertTrue(big_time >= small_time)

        self.assertTrue(small_time == small_time)
        self.assertFalse(small_time == big_time)
Exemple #6
0
def start_work_task(start_time: str, end_time: str, tags: List[str],
                    description: str, date: str):
    start = WdcTime(start_time)
    end = WdcTime(end_time) if end_time else None

    # If a date is provided then it has to be valid
    if not is_date_valid(date) and date != '':
        raise ValueError(f'{date} is not a valid date format')
    # When no date is provided then we assume "today"
    date = date if date else today()

    row_id = generate_hash(f'{start_time}{end_time}{description}')

    task_data = WdcTask(id=row_id,
                        date=date,
                        start=str(start),
                        end=str(end) if end is not None else '',
                        tags=array_to_tags_string(tags),
                        description=description)

    write_task(task_data)
Exemple #7
0
def end_last_task(date: str, time: str):
    if not is_date_valid(date):
        raise ValueError(f'{date} is not a valid date format')

    if time == '':
        time = str(WdcTime.now())

    if not is_time_valid(time):
        raise ValueError(f'{date} is not a valid date format')

    task = last_task(date)

    task.end = time
    task.timestamp = timestamp()

    write_task(task)
Exemple #8
0
 def test_add_minutes_carry_the_hour(self):
     test_object = WdcTime("0830")
     test_object.add_minutes(31)
     self.assertEqual(test_object.minutes, "01")
     self.assertEqual(test_object.hours, "09")
Exemple #9
0
def sort_by_time(tasks: List[WdcTask],
                 descending: bool = False) -> List[WdcTask]:
    return sorted(tasks,
                  key=lambda t: hash(WdcTime(t.start)),
                  reverse=descending)
Exemple #10
0
 def test_add_hours_stays_in_same_day(self):
     test_object = WdcTime("0800")
     test_object.add_hours(5)
     self.assertEqual(test_object.hours, "13")
Exemple #11
0
 def test_add_hours_next_day(self):
     test_object = WdcTime("1300")
     test_object.add_hours(13)
     self.assertEqual(test_object.hours, "02")
Exemple #12
0
 def test_now_one_digit(self):
     test_object = WdcTime.now()
     self.assertEqual('0808', str(test_object))
Exemple #13
0
 def setUp(self):
     self.time = WdcTime("1240")
Exemple #14
0
 def test_now_two_digit(self):
     test_object = WdcTime.now()
     self.assertEqual('1516', str(test_object))
Exemple #15
0
 def test_add_hours_midnight(self):
     test_object = WdcTime("1200")
     test_object.add_hours(12)
     self.assertEqual(test_object.hours, "00")
Exemple #16
0
 def test_add_minutes(self):
     test_object = WdcTime("0800")
     test_object.add_minutes(30)
     self.assertEqual(test_object.minutes, "30")
Exemple #17
0
 def test_add_hours_negative_hours(self):
     test_object = WdcTime("1200")
     test_object.add_hours(-3)
     self.assertEqual(test_object.hours, "09")
Exemple #18
0
 def test_to_string(self):
     test_object = WdcTime("0835")
     self.assertEqual(test_object.__str__(), "0835")
Exemple #19
0
    def test_minutes(self):
        self.assertEqual("40", self.time.minutes)

        self.time = WdcTime("1300")
        self.assertEqual("00", self.time.minutes)