Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong updating date[time] attributes #180

Open
tieugene opened this issue Dec 17, 2021 · 0 comments
Open

Wrong updating date[time] attributes #180

tieugene opened this issue Dec 17, 2021 · 0 comments

Comments

@tieugene
Copy link

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'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant