prisma icon indicating copy to clipboard operation
prisma copied to clipboard

Improve Timezone Support for Existing MySQL Databases configured with a Non-UTC Timezone

Open jhaemin opened this issue 4 years ago • 123 comments

Bug description

The OS and MySQL time both are set to KST(Korea Standard Time) which is UTC+9:00. But when create or update records with new Date(), DATETIME string doesn't respect the database's timezone and always filled with UTC time.

For example, when the current time is 2020-06-20 13:00:00 in Korea, I expect the data should be stored like below

id created_at
1 2020-06-20 13:00:00

However, what I get is UTC time which differs -9 hours.

id created_at
1 2020-06-20 04:00:00

How to reproduce

  1. Set the system and MySQL timezone to Asia/Seoul or UTC+9:00

  2. Create with new Date()

await prisma.myTable.create({
  data: {
    createdAt: new Date()
  }
})

Expected behavior

I expect the DATETIME string to be synced with MySQL's timezone.

Prisma information

model MyTable {
  createdAt DateTime @map(name: "created_at")

  @@map(name: "my_table")
}

Environment & setup

  • OS: Ubuntu
  • Database: MySQL 8.0.20
  • Prisma version: 2.0.1
  • Node.js version: 13.14.0

jhaemin avatar Jun 20 '20 11:06 jhaemin