Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Post 저장 시 작성 시간이 잘못 저장되는 오류 #21

Description

@hatchling13

개요

게시글 작성 후 저장 시, PostViewSetwrite 함수에서 request에서 자료를 받아 post_data에 저장 후 serializer에 전달한다. 이 때, post_data의 값 중 date_created의 값이 잘못 설정되어 저장되는 오류를 해결한다,

문제 상황

post_data 생성 시 date_created의 값으로 datetime.now()의 값을 저장한다. datetime.now()는 시간대 정보 tz를 매개변수로 받아 현재 시각을 반환한다. 그리고 tzNone이거나 명시되지 않은 경우, 현재 사용하고 있는 컴퓨터의 시간대 정보를 이용해 현재 시각을 반환한다.

프론트엔드의 주 언어인 Javascript의 경우, 시간을 다룰 때 기본적으로 UTC를 사용한다. 따라서 백엔드에 저장되는 시간 또한 UTC로 저장해주어야 한다.

해결 방법

공식 문서에 따르면 다음과 같이 datetime.now()에 매개변수 tztimezone.utc로 지정하는 것이 바람직하다.

datetime.now(timezone.utc)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions