8000 Implementation of timedelta formatter · Issue #444 · dateutil/dateutil · GitHub
[go: up one dir, main page]

Skip to content
Implementation of timedelta formatter #444
@pganssle

Description

@pganssle

There is no equivalent of strftime for timedelta, so everyone tends to roll their own formatter. This is prime territory for dateutil, ideally it would be something like this:

>>> from dateutil import formatter
>>> from datetime import timedelta

>>> formatter.format(timedelta(hours=1), '%H:%m:%s') 
'01:00:00'
>>> formatter.format(timedelta(hours=-1, minutes=-30), '%H:%m:%s')
'-01:30:00'

I could also see using something similar to Python's .format formatting spec. Either way, the main questions are probably how to deal with the sign and precision of the delta, what components are supported, etc, and how rounding/precision cascades down. Preferably all of that would be encoded into the string itself, but it might be reasonable to add one or two global flags.

I think the actual implementation for this will be fairly straightforward, the main question is how to do the implementation. I have a strong preference for standards in this regard, rather than something we just make up ourselves, so if anyone has any citations for how this is done in general, please post them so we can discuss.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0