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

Serializer for timedelta #447

Closed
davetapley opened this issue Nov 28, 2023 · 2 comments
Closed

Serializer for timedelta #447

davetapley opened this issue Nov 28, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@davetapley
Copy link
Contributor

Thoughts on including a (de)serializer for timedelta out of the box?

As I hinted on #436 I'm doing it with isodate:

from isodate import parse_duration, duration_isoformat
from serde import field

def field_timedelta():
    return field(
        serializer=lambda d: None if d is None else duration_isoformat(d),
        deserializer=lambda s: None if s is None else parse_duration(s)
    )

... but I feel like it's sufficiently ISO that it could be included?


Related:

@yukinarit
Copy link
Owner

Hi @davetapley
timedelta could be included, but I prefer not using third party package just for this. Would you want to try contributing?

@yukinarit yukinarit added enhancement New feature or request good first issue Good for newcomers labels Jan 7, 2024
@yukinarit
Copy link
Owner

FYI @davetapley
Although timedelta should probably be implemented in pyserde itself, I fount it a good opportunity to experiment capability of new global custom (de)serializer. I published pyserde-timedelta package in PyPI. Please take a look if it's interesting for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants