viiviii / friendly-pancake

0 stars 0 forks source link

๐Ÿ› bug: ๋น„ํ™œ์„ฑํ™” ๋‚ ์งœ ์ €์žฅ ์‹œ ์‹œ๊ฐ„๋„ ํ•จ๊ป˜ ์ €์žฅํ•˜๋„๋ก ๋ณ€๊ฒฝํ•œ๋‹ค #103

Closed viiviii closed 6 months ago

viiviii commented 6 months ago

Fixed: #102

๋ณ€๊ฒฝ



๋ฉ”๋ชจ

ZonedDateTime ๋Œ€์‹  Instant ์‚ฌ์šฉ ์ด์œ 

์ฒ˜์Œ์—” ZonedDateTime์„ ์‚ฌ์šฉํ–ˆ์œผ๋‚˜ ์•„๋ž˜์˜ ํ…Œ์ŠคํŠธ๊ฐ€ ํ•˜๋‚˜๊ฐ€ ์‹คํŒจํ–ˆ๋‹ค

image

ZonedDateTime์€ ๋‚ด๋ถ€์ ์œผ๋กœ ZoneId.systemDefault()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ zoneId๋ฅผ ํŒŒ์•…ํ•œ ๋’ค toString()์—์„œ ํฌํ•จํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

image

ZonedDateTime์€ zone์„ ํฌํ•จํ•œ ํ…์ŠคํŠธ์˜ parsing๋„ ๊ฐ€๋Šฅํ•˜๊ณ , ๋กœ๊ทธ ๊ฐ™์€ ๊ฑธ ํ™•์ธํ•  ๋•Œ๋„ ํ•ด๋‹น ์„œ๋ฒ„ ์„ค์ •์— ๋งž์ถฐ ๋ณด์—ฌ์ฃผ๋Š” ๊ฒƒ์ด ํŽธํ•  ์ˆ˜ ์žˆ๋‹ค๊ณค ์ƒ๊ฐํ•˜๋Š”๋ฐ, ๋‚˜์—๊ฒ ๋ณ„๋กœ ํ•„์š”ํ•˜์ง„ ์•Š์•„์„œ ํŒจ์Šคํ–ˆ๋‹ค.

๊ทธ ๋‹ค์Œ์— ์ฐพ์•„๋ณธ Instant๊ฐ€ ๋‚ด๊ฐ€ ์›ํ•˜๋˜ ๊ฑฐ ์˜€๋‹ค.

์ฒ˜์Œ์—” 1970-01-01T00:00:00Z ์ดํ›„์˜ ์ดˆ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค๊ณ  ํ•ด์„œ long ํƒ€์ž…์œผ๋กœ ์‚ฌ์šฉํ• ๊นŒ๋ด ํŒจ์Šค ํ–ˆ์—ˆ๋Š”๋ฐ toString()์ด ๋‚ด๊ฐ€ ์›ํ•˜๋˜ ISO-8601 ๋ฐฉ์‹์œผ๋กœ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ๋˜์–ด์žˆ์—ˆ๋‹ค.


Instant์™€ UTC


PostgreSQL๊ณผ timezone

์ฒ˜์Œ์—” ๋ชจ๋ฅด๊ณ  ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ZonedTimeZone์˜ ๊ฐ’์„ UTC๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ DB์— ์ €์žฅํ–ˆ์—ˆ๋‹ค.

ํ•˜์ง€๋งŒ, ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•ด์„œ ๋””๋ฒ„๊น… ํ•˜๋‹ค๊ฐ€ ์‹คํ–‰ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋”ฐ๋ผ ๊ฐ’์ด ๋‹ค๋ฅด๋‹ค๋Š” ๊ฑธ ์•Œ๊ฒŒ๋๋‹ค.

image

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.

When a timestamp with time zone value is output, it is always converted from UTC to the current timezone zone, and displayed as local time in that zone

๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ ๋‚ด๋ถ€์ ์œผ๋กœ๋Š” UTC๋กœ ์ €์žฅํ•˜๊ณ  ์ถœ๋ ฅ ์‹œ์— ํ•ด๋‹น zone์˜ ํ˜„์ง€ ์‹œ๊ฐ์œผ๋กœ ๋ณ€ํ™˜๋œ๋‹ค๊ณ  ํ•œ๋‹ค.


Bean๊ณผ static

now ๋ฉ”์„œ๋“œ์˜ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด now(Clock...) api๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ clock์„ DI ๋ฐ›๋„๋ก ๋ณ€๊ฒฝํ–ˆ๋‹ค. ์•„์ง์€ ๋”ฐ๋กœ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ํ•„์š”๊ฐ€ ์—†์„ ๊ฒƒ ๊ฐ™์•„ ๋ฉ”์„œ๋“œ๋กœ ์ฃผ์ž…๋ฐ›๊ฒŒ ํ–ˆ๋Š”๋ฐ ์ˆœํ™˜์ฐธ์กฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ์ƒ๊ฐํ•ด๋ณด๋ฉด ํ•ด๋‹น ํด๋ž˜์Šค๋ฅผ bean์œผ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ•˜๋Š”๋ฐ ๊ทธ ์ธ์Šคํ„ด์Šค์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฒƒ์ด์—ˆ๋‹ค.

๊ทธ๋ž˜์„œ inner class๋ฅผ ๋งŒ๋“ค๊นŒ ํ•˜๋‹ค๊ฐ€ Bean ๋ฌธ์„œ์—์„œ static ๋ฌธ๊ตฌ๋ฅผ ์ฝ๊ณ  ๋”ฐ๋ผํ–ˆ์Œ