Prisma1: changed timezone doesn't work

Created on 31 Aug 2018  路  3Comments  路  Source: prisma/prisma1

Describe the bug
Hi
prisma is very useful for me, but I have a problem about the timezone of datetime field.
I have no idea to change default timezone.

when insert data by prisma, createdAt and updatedAt field use UTC timezone datetime,
even if I have changed the mysql timezone to Asia/Shanghai

To Reproduce

  1. my date shema:
type Config {
  id: ID! @unique

  code: String
  name: String
  value: Float

  createdAt: DateTime!
  updatedAt: DateTime!
}
  1. the timezone of mysql docker container is changed:
$ docker exec deploy_db_1 date
Fri Aug 31 10:03:19 CST 2018
  1. but inserted date still 8 hours before that:
    insert query:
mutation {
  createConfig(data: { code: "sxx", name: "xxx", value: 0.9 }) {
    id
    updatedAt
    createdAt
  }
}

json response:

{
  "data": {
    "createConfig": {
      "id": "cjlhcteh700060b78hvce6zgf",
      "updatedAt": "2018-08-31T02:03:19.053Z",
      "createdAt": "2018-08-31T02:03:19.053Z"
    }
  }
}

Expected behavior
I expect json response will be:

{
  "data": {
    "createConfig": {
      "id": "cjlhcteh700060b78hvce6zgf",
      "updatedAt": "2018-08-31T10:03:19.053Z",
      "createdAt": "2018-08-31T10:03:19.053Z"
    }
  }
}

Versions (please complete the following information):

  • OS: debian 9
  • prisma CLI: prisma/1.15.1 (linux-x64) node-v8.11.4]
  • Prisma Server: 1.15.1
  • graphql-cli : 2.16.5,
  • prisma-binding: 2.1.4
  • graphql-yoga: 1.16.1

Most helpful comment

BTW, please change "is not work" to "doesn't work" 馃槈

All 3 comments

I am having the same situation.
But I discovered that Prisma uses the UTC time explicitly (that is, for example, in: 2018-08-31T02:03:19.053Z the 'Z' indicates that the timezone is UTC).
So I can use a time manipulation library like Moment to convert to local time without any problems.
Please devs, you should consider adding this to the documentation. (if it isn't already).

Anyway, I wrote a guide below to change the timezone inside the docker containers. This should also be interesting to put in the Prisma docs.

I tried configuring both docker containers (one is for mysql, the other one for the Prisma server):

  1. MYSQL container
#Get the ID of the mysql container
docker container ls 
docker exec -it {MYSQL_CONTAINER_ID} bash

sudo echo "Asia/Shanghai" > /etc/timezone
sudo dpkg-reconfigure -f noninteractive tzdata
#check if the time is set correctly
date

mysql -uroot -pprisma

Inside MySQL, run the queries below in order to verify if timezone is set correctly.

SELECT NOW();
SELECT @@global.time_zone, @@session.time_zone;

The timezone should be "SYSTEM", that is, configured by the system and not by mysql.

  1. Prisma container
    Connect to the container using the command below:
docker container ls
docker exec -it {PRISMA_CONTAINER_ID} bash

Then follow this tutorial for changing the timezone (the prisma container is based on Alpine Linux):
https://wiki.alpinelinux.org/wiki/Setting_the_timezone

Still, the createdAt and updatedAt fields are set according to UTC time, not the local time.

BTW, please change "is not work" to "doesn't work" 馃槈

I have changed the title , thank you for your reply! @stefanfuchs : )
I will follow your advice to use a time manipulation library like Moment to convert to local time.
thanks again about your detail advice!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tbrannam picture tbrannam  路  3Comments

ragnorc picture ragnorc  路  3Comments

hoodsy picture hoodsy  路  3Comments

MitkoTschimev picture MitkoTschimev  路  3Comments

schickling picture schickling  路  3Comments