Skip to content

seems like timezone doesn't work #3768

Closed

Description

@PavloPoliakov

Hi,

Just found out, that the values from our PostgreSQL are selected despite the timezone configuration option, which is set by default to '00:00'.

The selected values look like:

{ id: '15',
  xxx: 'xxx',
  created_date: Sat May 16 2015 04:00:46 GMT+0200 (CEST),
  due_date: Sat Apr 18 2015 00:00:00 GMT+0200 (CEST),
  xxx: '-xxx',
  xxx: null,
  xxx: 'xxx',
  xxx: 'xxx',
  xxx: null }

How to check that _timezone_ is indeed working?

Regards,

Activity

  1. mickhansen commented on May 20, 2015

    @mickhansen
    Contributor

    @PavelPolyakov The output you provided doesn't actually show that the dates are wrong. You are likely logging a javascript date object which will usually display in your local time zone.

    You can verify it's indeed working by looking at the raw data instead.

  2. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    @mickhansen
    In the postgreSQL the data stored like timestamp

        created_date TIMESTAMP,
        due_date TIMESTAMP,

    What I log is:

    console.log(record.toJSON());

    Is something wrong with my approach ?

  3. mickhansen commented on May 20, 2015

    @mickhansen
    Contributor

    What's the raw value in postgres? If it's Sat May 16 2015 06:00:46 then it's correct, if not there's a bug.
    @PavelPolyakov You are logging javascript date objects, so you can't expect them to have 00:00 as timezone (they'll use your local timezone), but they should work fine with UTC values, converting them internally.

  4. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    @mickhansen
    Here are the database values:
    image

  5. mickhansen commented on May 20, 2015

    @mickhansen
    Contributor

    Then it does appear to be a bug.
    You'll have to share your configuration etc, maybe @janmeier can help.

  6. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    My sequelize connection looks the next way:

    var sequelize = new Sequelize(config.get('database.database'), config.get('database.username'), config.get('database.password'), {
        dialect:  'postgres',
        protocol: 'postgres',
        port:     config.get('database.port'),
        host:     config.get('database.host'),
        logging:  debug, //false
    
        timezone:'+00:00',
    
        dialectOptions: {
            ssl: true
        },
    
        pool: {
            max: 20,
            min: 0,
            idle: 5000
        }
    });

    That's the table DDL:

    CREATE TABLE xxx_xxx
    (
        id SERIAL DEFAULT nextval('seq_seq'::regclass) NOT NULL,
        uuu BIGINT,
        created_date TIMESTAMP,
        due_date TIMESTAMP,
        xxx BIGINT,
        yyy VARCHAR(100),
        qqq VARCHAR(100),
        www BIGINT,
        eee BIGINT,
        rrr VARCHAR(255),
        ttt BIGINT
    );

    @janmeier
    Please, advice either how should I doublecheck if the timezone is working or - which information I can provide you in addition.

  7. janmeier commented on May 20, 2015

    @janmeier
    Member

    Sequelize expects timestamp with timezone in postgres
    On May 20, 2015 4:42 PM, "Pavel" [email protected] wrote:

    My sequelize connection looks the next way:

    var sequelize = new Sequelize(config.get('database.database'), config.get('database.username'), config.get('database.password'), {
    dialect: 'postgres',
    protocol: 'postgres',
    port: config.get('database.port'),
    host: config.get('database.host'),
    logging: debug, //false

    timezone:'+00:00',
    
    dialectOptions: {
        ssl: true
    },
    
    pool: {
        max: 20,
        min: 0,
        idle: 5000
    }
    

    });

    That's the table DDL:

    CREATE TABLE xxx_xxx
    (
    id SERIAL DEFAULT nextval('seq_seq'::regclass) NOT NULL,
    uuu BIGINT,
    created_date TIMESTAMP,
    due_date TIMESTAMP,
    xxx BIGINT,
    yyy VARCHAR(100),
    qqq VARCHAR(100),
    www BIGINT,
    eee BIGINT,
    rrr VARCHAR(255),
    ttt BIGINT
    );

    —
    Reply to this email directly or view it on GitHub
    #3768 (comment)
    .

  8. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    @janmeier
    So, if there is a timestamp without the timezone, then sequelize would put the current node timezone?

    Could we do something about it? Together with hapijs issue ( hapijs/hapi#2542 ) it makes a time shift, which we doesn't expect to have :)

    Any advice?

  9. janmeier commented on May 20, 2015

    @janmeier
    Member

    Technically, sequelize does not, node pg does - since it automatically converts the string from the db to a date object, assuming that the date is in the current timezone of the server. This is an implementation detail of javascript.

    There is another issue relating to this with a fix included. I'll try to find it in a bit

  10. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    @janmeier
    Thanks, looking forward for the link.

  11. janmeier commented on May 20, 2015

    @janmeier
    Member

    http://docs.sequelizejs.com/en/latest/docs/models-definition/#data-types looks for the setTypeParser part

    I believe I had a discussion with someone about integrating this code into sequelize. There was a reason not to do it, but I can find the issue or remember the reasoning right now :)

  12. PavloPoliakov commented on May 20, 2015

    @PavloPoliakov
    ContributorAuthor

    @janmeier
    Thanks!

  13. PavloPoliakov commented on May 24, 2015

    @PavloPoliakov
    ContributorAuthor

    btw,

    how we've solved it:

    var postgres = require('pg');
    
    postgres.types.setTypeParser(1114, function(stringValue) {
        return moment(stringValue).format('YYYY-MM-DD HH:mm:ss');
    });

    The one from the link was not working.

  14. janmeier commented on May 24, 2015

    @janmeier
    Member

    But won't that return a string and not a date object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions