[storm] storm + datetime + TZ behavior

IvO ivo.munoz at gmail.com
Fri Jul 30 01:02:43 BST 2010


Dear All,

        first of all, congratulations for a very good product.

        I'm a bit confused by STORM/Postgres behavior regarding timestamp
        fields.

        In short, I get timestamps in localtime() and try to store them in the
        DB as UTC. However a select on the DB shows that timestamps are still in
        localtime, as follows:


        dlproj=# SELECT  * from dlv_datavalue where id=430;
         id  | site_id | subject_id |       timestamp        | rawvalue | value
        -----+---------+------------+------------------------+----------+-------
         430 |       1 |          1 | 1997-01-24 13:48:30-03 |      2.1 |   2.1
        (1 row)

        I'd have expected the timestamp field has a +00 offset instead it still
        has the -03 offset.

        As explained above, data is inserted into the table with a python script
        (using storm), I  receive timestamps in localtime (whatever that is,
        currently GMT-4) and try to store them in the database as UTC, as
        follows:

        ts = datetime.datetime.strptime('T'.join((d,t)),
                                         '%Y-%m-%dT%H:%M:%S.%f')
        ts = ts.replace(tzinfo = tz)
        print ts, ts.astimezone(utc)
        tsutc =  ts.astimezone(utc)

        where tz is the local time zone and utc is UTC timezone gathered from
        storm.tz.tzutc().


        So, can someone tell me what's wrong?
        If you have readed this far the table definition is as follows (django
        creates it from my model file).

        CREATE TABLE "dlv_datavalue" (
            "id" serial NOT NULL PRIMARY KEY,
            "site_id" integer NOT NULL REFERENCES "dlv_site" ("id") DEFERRABLE
        INITIALLY DEFERRED,
            "subject_id" integer NOT NULL REFERENCES "dlv_measurement" ("id")
        DEFERRABLE INITIALLY DEFERRED,
            "timestamp" timestamp with time zone NOT NULL,
            "rawvalue" double precision NOT NULL,
            "value" double precision NOT NULL,
            UNIQUE ("site_id", "subject_id", "timestamp")
        )


        many thanks in advance
        IvO



More information about the storm mailing list