본문 바로가기

컴퓨터/JavaScript

TypeORM 타임존 옵션 관련 Timezone option

TypeORM을 사용해 작업중에 TypeORM이 테이블에서 가져오는 값과 실제 테이블 내 컬럼값이 상이함을 발견했다. 

 

예를들어 DB 내 실제 값은 2021-09-04 00:00:00 인데,

이 값을 TypeORM으로 가져왔을 때는 2021-09-03 15:00:00으로 변경되어 있었다.

 

처음에는 서버 리눅스 내부의 timezone이 상이해서 그런줄 알았는데, 똑같이 seoul로 맞춰봐도 동일했다.

혹시 ORM 수준에서 변환을 하고 있지 않을까 해서 찾아보니, 관련한 Github issue에서 해결법을 발견했다. 

 

코드 상에서 DB 연결을 위한 ORM 설정 부분에서 timezone 파라미터를 추가해주면 된다.

const connectionInfo = ({ 
  type: 'mysql',
  name: 'mysql',
  port: config.jdbc.port,
  host: config.jdbc.host,
  username: config.jdbc.user,
  password: config.jdbc.password,
  database: config.jdbc.database,

  timezone: 'Z',

  synchronize: false,
  entities: [__dirname + '/sql/*{.js,.ts}']
} 
as MysqlConnectionOptions);

 

 

관련링크 : 

https://github.com/typeorm/typeorm/issues/976#issuecomment-386925989

 

Is it internally converting the date object to UTC before saving. · Issue #976 · typeorm/typeorm

I have an entity like this: @Entity('jobs') export class Job { @Column(type => DateTimeWithOffset) start: DateTimeWithOffset; } export class DateTimeWithOffset { @Column({ name: '_of...

github.com

Github issue 에서 좋은 이모티콘이 많은 걸 발견하면 기분이 좋아진다..

'컴퓨터 > JavaScript' 카테고리의 다른 글

express router의 next() 관련...  (0) 2020.09.25
vue.js 디렉티브 기초  (0) 2020.09.24
Vue.js 특징  (0) 2020.09.24