On Jul 6, 5:21 pm, [email protected] 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
--
http://mail.python.org/mailman/listinfo/python-list