Skip to content

Wrong updating date[time] attributes #180

Description

@tieugene

I met this when tried to update 'Due' and 'DTStart' fields of VTODOs from date to datetime and vice versa.
Behaviour is very strange (try to update date<>datetime, naive datetime <> timezoned datetime etc).

#!/usr/bin/env python3
# Test Date[time] fields of vobject
import datetime, vobject

def just_due(vcal: str):
    for s in vcal.split():
        if s.startswith('DUE'):
            return s

# Stage 1: create vtodo with due:date
vobj = vobject.iCalendar()
vobj.add('vtodo')
vobj.vtodo.add("due").value = datetime.datetime.now().date()
s = vobj.serialize()
print(type(vobj.vtodo.due.value), just_due(s))
# Stage 2: change due: date>datetime
vobj = vobject.readOne(s)
now = datetime.datetime.now()
vobj.vtodo.due.value = now
s = vobj.serialize()
print(type(now), "=>", type(vobj.vtodo.due.value), just_due(s))
# Stage 3: read result
vobj = vobject.readOne(s)
print(type(vobj.vtodo.due.value))

Result:

<class 'datetime.date'> DUE;VALUE=DATE:20211217
<class 'datetime.datetime'> => <class 'datetime.date'> DUE;VALUE=DATE:20211217T190416
<class 'datetime.date'>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions