﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25060	Add support for str(timedelta) representation in parse_duration	Mikhail	nobody	"It's useful for conversions to/from str, so we can convert timedelta value to str and back without additional work.
The following code can be used instead of original parse_duration function
{{{
# Support str(timedelta) format
str_timedelta_duration_re = re.compile(
    r'^'
    r'(?:(?P<days>-?\d+) days*, )?'
    r'((?:(?P<hours>\d+):)(?=\d+:\d+))?'
    r'(?:(?P<minutes>\d+):)?'
    r'(?P<seconds>\d+)'
    r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
    r'$'
)

def parse_duration(value):
    """"""Parses a duration string and returns a datetime.timedelta.

    The preferred format for durations in Django is '%d %H:%M:%S.%f'.

    Also supports ISO 8601 and str(timedelta) representations.
    """"""
    for duration_re in (standard_duration_re, iso8601_duration_re, str_timedelta_duration_re):
        match = duration_re.match(value)
        if match:
            kw = match.groupdict()
            if kw.get('microseconds'):
                kw['microseconds'] = kw['microseconds'].ljust(6, '0')
            kw = {k: float(v) for k, v in six.iteritems(kw) if v is not None}
            return datetime.timedelta(**kw)
}}}
"	New feature	closed	Utilities	dev	Normal	fixed		Mikhail Marc Tamlyn	Accepted	1	1	1	0	0	0
