alonho/pql

parse date("...") as timestamp

calmrat opened this issue · 5 comments

Parsing a query using the date() function returns a spec clause which using datetime object. I need to use a timestamp (epoc seconds) in place of a datetime.

IS:
date_field >= date("1998-01-01") == {'date_field': {'$gte': datetime.datetime(1998, 1, 1, 0, 0)}}

WAS:
date_field >= date("1998-01-01") == {'date_field': {'$gte': 883612800}}

eg::
from datetime import datetime
from calendar import timegm
dt = datetime(1998, 1, 1, 0, 0)
ts = timegm(dt.timetuple())

Perhaps an argument could be set when calling parse, where by default the parse would return datetime objects, or epoch timestamp if epoch=True? Or configurable option set somewhere? at parser init?

pql_parser = pql.SchemaFreeParser()
spec = pql_parser.parse(query, epoch=True)

oh, funny, i see in current master there's epoch() func... i'll update and see if it doesn't happen to do exactly what i'm interesting in ...

and it does. So... open and closed. Thanks! :) Great work!

current pypi version doesn't seem to be in-line with master, will you push a new version to pip anytime soon?

I'll do it tomorrow

Thanks!

I'm going to also reopen this with a request to pull in epoch_utc for generating epoch using utc tz instead of localtime.

calmrat@de6274e