Due date specified as DATE is changed to DATETIME with year 1900
fwc opened this issue · comments
I have a todo with due date 21.04, specified as DUE;VALUE=DATE:20210421
in the .ics
-file.
When I open this todo with todo edit <id>
and save it again directly, without changes, the due date is changed to DUE;VALUE=DATE-TIME:19000420T230000Z
.
So my todo is now due on 21.04.1900.
.ics
-file before editing with todoman
BEGIN:VCALENDAR
VERSION:2.0
PRODID:+//IDN tasks.org//android-110903//EN
BEGIN:VTODO
DTSTAMP:20210420T111823Z
UID:3643130479634528538
CREATED:20210420T105907Z
LAST-MODIFIED:20210420T111805Z
SUMMARY:Test
X-APPLE-SORT-ORDER:608725011
DUE;VALUE=DATE:20210421
END:VTODO
END:VCALENDAR
.ics
-file after editing with todoman
BEGIN:VCALENDAR
VERSION:2.0
PRODID:+//IDN tasks.org//android-110903//EN
BEGIN:VTODO
CREATED;VALUE=DATE-TIME:20210420T105907Z
DTSTAMP;VALUE=DATE-TIME:20210420T111823Z
DUE;VALUE=DATE-TIME:19000420T230000Z
LAST-MODIFIED;VALUE=DATE-TIME:20210420T112108Z
SEQUENCE:2
STATUS:NEEDS-ACTION
SUMMARY:Test
UID:3643130479634528538
X-APPLE-SORT-ORDER:608725011
END:VTODO
END:VCALENDAR
for reproducing, set date_format
in the configuration to date_format = "%d.%m."
.
The initial date (2021-04-21
) is then displayed in this format ("21.04."
), and 'parsed back' into a datetime-object when saving, but the year is lost during the process.
When re-parsing the date, we run into the following code in interactive.py
:
def _save_inner(self):
# ...
self.todo.due = self.formatter.parse_datetime(self.due)
# ...
- Before this line,
self.todo.due
is still the initialdatetime.date
-object (2021-04-21
). self.due
is the string value that was displayed, which in turn is the formatteddate
-object:"21.04."
.- During parsing,
self.due
matches thedate_format
, so it's parsed withdatetime.strptime
, which sets the year to 1900:-
>>> datetime.strptime("21.04.", "%d.%m.") # returns: datetime.datetime(1900, 4, 21, 0, 0)
-