Ejemplo n.º 1
0
def inflate_date(text, dates, default):
    if text in dates:
        return dates[text]
    elif not text or not text.strip():
        return default
    date = parse_datetime(text, dates["today"])
    if not date:
        return default
    return date
Ejemplo n.º 2
0
def test_parse_datetime(input, expected):
    result = parse_date.parse_datetime(input, today)
    if isinstance(expected, datetime.datetime):
        assert result == expected
    elif isinstance(expected, dict):
        dct = todaydct.copy()
        dct.update(expected)
        assert result == datetime.datetime(**dct)
    elif not expected:
        assert not result
Ejemplo n.º 3
0
def expand_string(text, today):
    '''A collapsed string looks like "title|id|created|modified|completed"'''
    if not text.strip():
        return None
    parts = map(str.strip, text.split("|"))
    data = {"name": parts[0]}
    if len(parts) > 1:
        data["id"] = parse_id(parts[1])
    if len(parts) > 2:
        data["created"] = parse_datetime(parts[2], today)
    if len(parts) > 3:
        data["modified"] = parse_datetime(parts[3], today)
    if len(parts) > 4:
        data["completed"] = parse_datetime(parts[4], today)
    if data.get("created", None) is None:
        data["created"] = today
    if data.get("modified", None) is None:
        data["modified"] = today
    return new_task(data)