On Jul 6, 8:43 pm, Carl Banks <pavlovevide...@gmail.com> wrote:
> On Jul 6, 5:21 pm, m...@pixar.com wrote:
>
> > I'm looking for something like Tcl's [clock scan] command which parses
> > human-readable time strings such as:
>
> >     % clock scan "5 minutes ago"
> >     1246925569
> >     % clock scan "tomorrow 12:00"
> >     1246993200
> >     % clock scan "today + 1 fortnight"
> >     1248135628
>
> > Does any such package exist for Python?
>
> If you're on a machine with GNU datethe simplest solution is to use it
> to parse the string.
>
> Q&D:
>
> def clock_scan(datestring):
>     stdout,stderr = subprocess.Popen(
>         ['date','+%s','--date=%s' % datestring ],
>         stdout=subprocess.PIPE).communicate()
>     return float(stdout)
>
> clock_scan('1 hour ago')
> clock_scan('next week')
>
> Carl Banks

The timelib module might do what you want
http://pypi.python.org/pypi/timelib/0.2
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to