示例#1
0
def validate_date_callback(ctx, param, value):
    if not param.required and value == '':
        return value
    if is_date_valid(value):
        return value
    else:
        return today()
示例#2
0
def amend_task(task_id: str,
               tags: List[str] = [],
               start: str = '',
               end: str = '',
               message: str = '',
               date: str = ''):
    if start != '' and not is_time_valid(start):
        raise ValueError(f'The start time {start} is not a valid time')

    if end != '' and not is_time_valid(end):
        raise ValueError(f'The end time {end} is not a valid time')

    if date != '' and not is_time_valid(date):
        raise ValueError(f'The given date {date} is not valid')

    task_info = get_task_info(task_id)

    if task_info is None:
        raise ValueError(
            f'The given task id {task_id} did not resolve to a task')

    task = task_info.current

    task.timestamp = timestamp()
    task.tags = array_to_tags_string(tags) if tags else task.tags
    task.start = start if is_time_valid(start) else task.start
    task.end = end if is_time_valid(end) else task.end
    task.description = message if message else task.description
    task.date = date if is_date_valid(date) else task.date

    write_task(task)
示例#3
0
文件: io.py 项目: dejanfajfar/wdc
def read_all_tasks(date: str) -> List[WdcTask]:
    if not is_date_valid(date):
        raise ValueError(f'{date} is not a valid date')

    file_path = task_file_path(date)

    if not file_path.exists():
        return []

    with open(str(file_path), 'r') as file:
        return list(
            map(lambda x: to_task(x), list(csv.reader(file, delimiter=';'))))
示例#4
0
文件: io.py 项目: dejanfajfar/wdc
def last_task(date: str) -> WdcTask:
    if not is_date_valid(date):
        raise ValueError(f'{date} is not a valid date')

    file_path = task_file_path(date)

    if not file_path.exists():
        raise FileNotFoundError(str(file_path))

    with open(str(file_path), 'r') as file:
        row = list(csv.reader(file, delimiter=';'))[-1]
        return to_task(row)
示例#5
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)
示例#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)
示例#7
0
def list_tasks(date: str, show_all: bool) -> List[WdcTask]:
    if not is_date_valid(date):
        raise ValueError(f'{date} is not a valid date format')

    tasks = read_all_tasks(date)

    tasks = list(filter(lambda t: t.date == date, tasks))

    if show_all:
        return sorted(tasks, key=lambda t: int(t.timestamp))

    else:
        return_tasks = {}
        for task in tasks:
            if task.id not in return_tasks:
                return_tasks[task.id] = task
            else:
                if int(return_tasks[task.id].timestamp) < int(task.timestamp):
                    return_tasks[task.id] = task
                else:
                    continue

        return sort_by_time(return_tasks.values())
示例#8
0
文件: io.py 项目: dejanfajfar/wdc
def task_file_path(date: str):
    if not is_date_valid(date):
        raise ValueError(f'{date} is not a valid date')

    return Path.joinpath(HOME_DIR_PATH, f'{to_date_no_day(date)}.csv')
示例#9
0
 def test_invalid(self):
     self.assertFalse(is_date_valid('2000-7-1'))
     self.assertFalse(is_date_valid('1800-07-31'))
     self.assertFalse(is_date_valid('2000-40-01'))
     self.assertFalse(is_date_valid('2000-07-40'))
     self.assertFalse(is_date_valid(''))
示例#10
0
 def test_valid(self):
     self.assertTrue(is_date_valid('2020-10-25'))
     self.assertTrue(is_date_valid('1980-07-01'))