Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78228

Re: Timedelta constructor with string parameter

References <a63a4890-eeb3-495c-bb81-3c1bbb85bff2@googlegroups.com> <CANc-5Uyna==N5DyU5188TAaRw0FCv2Hkhuhd0C6LT-_foVai6g@mail.gmail.com>
From Felipe Menezes Machado <felipou@gmail.com>
Date 2014-09-23 19:15 +0200
Subject Re: Timedelta constructor with string parameter
Newsgroups comp.lang.python
Message-ID <mailman.14275.1411492570.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Sep 23, 2014 at 6:39 PM, Skip Montanaro <skip@pobox.com> wrote:

>
> On Tue, Sep 23, 2014 at 4:11 AM, <felipou@gmail.com> wrote:
>
>> I created some code recently to parse a string and create a timedelta
>> from it.
>
>
> Interesting. I notice that dateutil.parser.parse already understands you
> notation:
>
> >>> x = dateutil.parser.parse("5h32m15s")
> >>> x
> datetime.datetime(2014, 9, 23, 5, 32, 15)
>
> All that would be necessary is some way to tell it to generate a timedelta
> instead of a datetime. Might be better to feed changes back to the dateutil
> package maintainers.
>
>
Cool, thanks for the tip, I didn't know dateutil yet.

I looked at the code for the dateutil.parser.parse function, and under the
hood it is so much more than my function does. It accepts many different
formats, and also handles timezones. So I'd have to study it a little to
think of a way for it to generate timedelta objects instead of datetime
ones. But I'll definitely keep that in mind!

Felipe

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Timedelta constructor with string parameter felipou@gmail.com - 2014-09-23 02:11 -0700
  Re: Timedelta constructor with string parameter Skip Montanaro <skip@pobox.com> - 2014-09-23 11:39 -0500
  Re: Timedelta constructor with string parameter Felipe Menezes Machado <felipou@gmail.com> - 2014-09-23 19:15 +0200

csiph-web