EpocDotFr / todotxtio

Simple Python module to parse, manipulate and write Todo.txt data
https://epocdotfr.github.io/todotxtio/
Other
15 stars 9 forks source link

Fix creation_date bug #14

Open MaurizioBruetsch opened 5 years ago

MaurizioBruetsch commented 5 years ago

As mentioned in #9 the regex should always be the same whether the task is done or not. As the other PR wasn't touched for some months I'm hoping you would pull this one.

Thanks

seanbreckenridge commented 4 years ago

Not sure if this PR solves my bug, but in my todo.txt (which odesnt have the (x) to mark to see if the task is done or not), creation dates often dissapear. I've removed that for now, but heres a re-creation of the bug:

import os
import todotxtio

dirname = os.path.dirname(os.path.abspath(__file__))
todo_file: str = os.path.join(dirname, "todo.txt")

todo = todotxtio.Todo(
    text='Thank Guido for such an awesome programming language',
    priority='A',
    creation_date='2016-11-20'
)

print("Todo in memory before write:", todo, sep="\n")

todotxtio.to_file(todo_file, [todo])

print("Todo file contents after first write:", open(todo_file).read(), sep="\n")

todos = todotxtio.from_file(todo_file)

print("Todo in memory after read from written file", todos, sep="\n")

todotxtio.to_file(todo_file, todos)

print("Todo file contents after second write:", open(todo_file).read(), sep="\n")

Output:

Todo in memory before write:
(A) 2016-11-20 Thank Guido for such an awesome programming language
Todo file contents after first write:
(A) 2016-11-20 Thank Guido for such an awesome programming language
Todo in memory after read from written file
[(A) Thank Guido for such an awesome programming language]
Todo file contents after second write:
(A) Thank Guido for such an awesome programming language

When reading/writing back and forth from the todo.txt, the creation dates dissapear -- the regex fails to read the creation date.