correct usage of "duration"
This commit is contained in:
parent
80714978d3
commit
58f295cc54
3 changed files with 5 additions and 24 deletions
|
@ -12,7 +12,6 @@ from typing import Iterator
|
|||
|
||||
from caldav import Calendar
|
||||
from caldav.lib.error import ReportError
|
||||
from isodate import parse_duration
|
||||
from pydantic import BaseModel, validator
|
||||
from vobject.base import Component
|
||||
|
||||
|
@ -92,16 +91,14 @@ class CalEvent(BaseModel):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
print(data)
|
||||
|
||||
if "dtend" not in data:
|
||||
data["dtend"] = data["dtstart"]
|
||||
|
||||
if "duration" in data:
|
||||
try:
|
||||
dtstart = datetime.fromisoformat(data["dtstart"])
|
||||
duration = parse_duration(data["duration"])
|
||||
dtend = dtstart + duration
|
||||
|
||||
data["dtend"] = dtend.isoformat()
|
||||
data["dtend"] += data["duration"]
|
||||
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
_logger.warn(
|
||||
|
@ -110,7 +107,7 @@ class CalEvent(BaseModel):
|
|||
repr(data["dtstart"]),
|
||||
)
|
||||
|
||||
data["dtend"] = data["dtstart"]
|
||||
del data["duration"]
|
||||
|
||||
return cls.parse_obj(data)
|
||||
|
||||
|
|
17
api/poetry.lock
generated
17
api/poetry.lock
generated
|
@ -127,17 +127,6 @@ docs = ["jaraco.packaging (>=9)", "rst.linker (>=1.9)", "sphinx"]
|
|||
perf = ["ipython"]
|
||||
testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "isodate"
|
||||
version = "0.6.1"
|
||||
description = "An ISO 8601 date/time/duration parser and formatter"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[package.dependencies]
|
||||
six = "*"
|
||||
|
||||
[[package]]
|
||||
name = "lxml"
|
||||
version = "4.9.1"
|
||||
|
@ -407,7 +396,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=6)", "pytest-black (>=
|
|||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "6fb83bae86629a411b61f4964ac137fdaec272a89d6b02db6938269a8d1eef91"
|
||||
content-hash = "b25d37c0bf9187d599709a66e05d21c0df7da2b140373f6cd50b070ae2f073ab"
|
||||
|
||||
[metadata.files]
|
||||
anyio = [
|
||||
|
@ -454,10 +443,6 @@ importlib-metadata = [
|
|||
{file = "importlib_metadata-4.12.0-py3-none-any.whl", hash = "sha256:7401a975809ea1fdc658c3aa4f78cc2195a0e019c5cbc4c06122884e9ae80c23"},
|
||||
{file = "importlib_metadata-4.12.0.tar.gz", hash = "sha256:637245b8bab2b6502fcbc752cc4b7a6f6243bb02b31c5c26156ad103d3d45670"},
|
||||
]
|
||||
isodate = [
|
||||
{file = "isodate-0.6.1-py2.py3-none-any.whl", hash = "sha256:0751eece944162659049d35f4f549ed815792b38793f07cf73381c1c87cbed96"},
|
||||
{file = "isodate-0.6.1.tar.gz", hash = "sha256:48c5881de7e8b0a0d648cb024c8062dc84e7b840ed81e864c7614fd3c127bde9"},
|
||||
]
|
||||
lxml = [
|
||||
{file = "lxml-4.9.1-cp27-cp27m-macosx_10_15_x86_64.whl", hash = "sha256:98cafc618614d72b02185ac583c6f7796202062c41d2eeecdf07820bad3295ed"},
|
||||
{file = "lxml-4.9.1-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c62e8dd9754b7debda0c5ba59d34509c4688f853588d75b53c3791983faa96fc"},
|
||||
|
|
|
@ -18,7 +18,6 @@ tomli = "^2.0.1"
|
|||
tomli-w = "^1.0.0"
|
||||
uvicorn = "^0.18.3"
|
||||
webdavclient3 = "3.14.5"
|
||||
isodate = "^0.6.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
# pytest = "^5.2"
|
||||
|
|
Loading…
Reference in a new issue