From cd70d3b9c54aa07819f464b08c0dce500ab21d63 Mon Sep 17 00:00:00 2001 From: ksmfou98 Date: Fri, 27 Oct 2023 22:57:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20isomorphicDate=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pnp.cjs | 18 ++++++++++++++++++ apps/jurumarble/package.json | 1 + .../app/main/components/HotDrinkContainer.tsx | 5 +++-- .../main/components/HotDrinkVoteContainer.tsx | 5 +++-- packages/date/.eslintrc.js | 4 ++++ packages/date/index.ts | 1 + packages/date/package.json | 15 +++++++++++++++ packages/date/src/index.ts | 1 + packages/date/src/isomorphicDate.ts | 7 +++++++ yarn.lock | 11 +++++++++++ 10 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 packages/date/.eslintrc.js create mode 100644 packages/date/index.ts create mode 100644 packages/date/package.json create mode 100644 packages/date/src/index.ts create mode 100644 packages/date/src/isomorphicDate.ts diff --git a/.pnp.cjs b/.pnp.cjs index 98b767aa..4322f4a6 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -27,6 +27,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "name": "@mogakko/browser-api",\ "reference": "workspace:packages/browser-api"\ },\ + {\ + "name": "@mogakko/date",\ + "reference": "workspace:packages/date"\ + },\ {\ "name": "eslint-config-mogakko",\ "reference": "workspace:packages/eslint-config-mogakko"\ @@ -52,6 +56,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "ignorePatternData": "(^(?:\\\\.yarn\\\\/sdks(?:\\\\/(?!\\\\.{1,2}(?:\\\\/|$))(?:(?:(?!(?:^|\\\\/)\\\\.{1,2}(?:\\\\/|$)).)*?)|$))$)",\ "fallbackExclusionList": [\ ["@mogakko/browser-api", ["workspace:packages/browser-api"]],\ + ["@mogakko/date", ["workspace:packages/date"]],\ ["@mogakko/http-fetch", ["workspace:packages/http-fetch"]],\ ["@mogakko/prettier-config", ["workspace:packages/prettier-config"]],\ ["@monorepo/chooz", ["workspace:apps/chooz"]],\ @@ -4277,6 +4282,18 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "SOFT"\ }]\ ]],\ + ["@mogakko/date", [\ + ["workspace:packages/date", {\ + "packageLocation": "./packages/date/",\ + "packageDependencies": [\ + ["@mogakko/date", "workspace:packages/date"],\ + ["eslint", "npm:8.51.0"],\ + ["eslint-config-mogakko", "virtual:d5d96e77964400fc4762308f8b56a1eb5ff206383418a2fcee04c20f08ffa650ba95923737bcbe8ba72eafd60eb6e8fd7627ea8d76fd8bc62bc6c89e4b46b027#workspace:packages/eslint-config-mogakko"],\ + ["typescript", "patch:typescript@npm%3A4.9.3#~builtin::version=4.9.3&hash=d73830"]\ + ],\ + "linkType": "SOFT"\ + }]\ + ]],\ ["@mogakko/http-fetch", [\ ["workspace:packages/http-fetch", {\ "packageLocation": "./packages/http-fetch/",\ @@ -4365,6 +4382,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@monorepo/jurumarble", "workspace:apps/jurumarble"],\ ["@emotion/is-prop-valid", "npm:1.2.1"],\ ["@mogakko/browser-api", "workspace:packages/browser-api"],\ + ["@mogakko/date", "workspace:packages/date"],\ ["@mogakko/http-fetch", "workspace:packages/http-fetch"],\ ["@monorepo/hooks", "virtual:a9e685c95fc9c2c05e15b14465ecc20924383932b7a1aa62172e110ba174ebedc352c8daf5023eb54ef5f0a5595ca6cf8763ef2477e003ebd1850bfb16231d67#workspace:packages/hooks"],\ ["@monorepo/ui", "virtual:8ec4233c825b2c709f2ff549456a05fb98060d621f5df14748cda36fdb51190eccc2e438466f7464c85557cdad97eb73aa6580e78bca957a1149bfc58c6ddf34#workspace:packages/ui"],\ diff --git a/apps/jurumarble/package.json b/apps/jurumarble/package.json index bfea3fe2..bda096f4 100644 --- a/apps/jurumarble/package.json +++ b/apps/jurumarble/package.json @@ -19,6 +19,7 @@ "dependencies": { "@emotion/is-prop-valid": "^1.2.1", "@mogakko/browser-api": "workspace:*", + "@mogakko/date": "workspace:*", "@mogakko/http-fetch": "workspace:*", "@monorepo/hooks": "workspace:*", "@monorepo/ui": "workspace:*", diff --git a/apps/jurumarble/src/app/main/components/HotDrinkContainer.tsx b/apps/jurumarble/src/app/main/components/HotDrinkContainer.tsx index 3acf4eeb..bacda29f 100644 --- a/apps/jurumarble/src/app/main/components/HotDrinkContainer.tsx +++ b/apps/jurumarble/src/app/main/components/HotDrinkContainer.tsx @@ -1,18 +1,19 @@ 'use client'; +import { getIsomorphicDate } from '@mogakko/date'; import styled, { css } from 'styled-components'; import Carousel from './Carousel'; import useGetHotDrinkListService from '../services/useGetHotDrinkListService'; +const nowTime = getIsomorphicDate().getHours(); + function HotDrinkContainer() { const { data: hotDrinkList } = useGetHotDrinkListService(); if (!hotDrinkList) { return null; } - const nowTime = new Date().getHours(); - return ( <>

diff --git a/apps/jurumarble/src/app/main/components/HotDrinkVoteContainer.tsx b/apps/jurumarble/src/app/main/components/HotDrinkVoteContainer.tsx index 70929bf2..c8ab8d45 100644 --- a/apps/jurumarble/src/app/main/components/HotDrinkVoteContainer.tsx +++ b/apps/jurumarble/src/app/main/components/HotDrinkVoteContainer.tsx @@ -1,5 +1,6 @@ 'use client'; +import { getIsomorphicDate } from '@mogakko/date'; import Path from 'lib/Path'; import Image from 'next/image'; import { useRouter } from 'next/navigation'; @@ -7,6 +8,8 @@ import styled, { css } from 'styled-components'; import { useGetHotDrinkVoteService } from '../services/useGetHotDrinkVoteService'; +const nowTime = getIsomorphicDate().getHours(); + function HotDrinkVoteContainer() { const router = useRouter(); @@ -16,8 +19,6 @@ function HotDrinkVoteContainer() { } const { voteId, voteTitle, drinkAImage, drinkBImage } = hotDrinkVote; - const nowTime = new Date().getHours(); - return ( <>

diff --git a/packages/date/.eslintrc.js b/packages/date/.eslintrc.js new file mode 100644 index 00000000..5e17feff --- /dev/null +++ b/packages/date/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + extends: ["mogakko"], + root: true, +}; diff --git a/packages/date/index.ts b/packages/date/index.ts new file mode 100644 index 00000000..3bd16e17 --- /dev/null +++ b/packages/date/index.ts @@ -0,0 +1 @@ +export * from "./src"; diff --git a/packages/date/package.json b/packages/date/package.json new file mode 100644 index 00000000..d2efca87 --- /dev/null +++ b/packages/date/package.json @@ -0,0 +1,15 @@ +{ + "name": "@mogakko/date", + "version": "0.1.0", + "license": "MIT", + "sideEffects": false, + "scripts": { + "eslint": "eslint -c .eslintrc.js --ignore-path ../../.eslintignore --ext .js,.jsx,.ts,.tsx . --cache", + "eslint:fix": "yarn eslint --fix" + }, + "devDependencies": { + "eslint": "^8.51.0", + "eslint-config-mogakko": "workspace:*", + "typescript": "4.9.3" + } +} diff --git a/packages/date/src/index.ts b/packages/date/src/index.ts new file mode 100644 index 00000000..e7a2a04d --- /dev/null +++ b/packages/date/src/index.ts @@ -0,0 +1 @@ +export * from './isomorphicDate'; diff --git a/packages/date/src/isomorphicDate.ts b/packages/date/src/isomorphicDate.ts new file mode 100644 index 00000000..64025450 --- /dev/null +++ b/packages/date/src/isomorphicDate.ts @@ -0,0 +1,7 @@ +/** + * @description 클라이언트, 서버에서 동일한 시간을 반환해주는 함수 + */ +export const getIsomorphicDate = (timeZone = 'Asia/Seoul') => { + const time = new Date().toLocaleString('en-US', { timeZone }); + return new Date(time); +}; diff --git a/yarn.lock b/yarn.lock index 201dbb86..f90c0a88 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1679,6 +1679,16 @@ __metadata: languageName: unknown linkType: soft +"@mogakko/date@workspace:*, @mogakko/date@workspace:packages/date": + version: 0.0.0-use.local + resolution: "@mogakko/date@workspace:packages/date" + dependencies: + eslint: ^8.51.0 + eslint-config-mogakko: "workspace:*" + typescript: 4.9.3 + languageName: unknown + linkType: soft + "@mogakko/http-fetch@workspace:*, @mogakko/http-fetch@workspace:packages/http-fetch": version: 0.0.0-use.local resolution: "@mogakko/http-fetch@workspace:packages/http-fetch" @@ -1744,6 +1754,7 @@ __metadata: dependencies: "@emotion/is-prop-valid": ^1.2.1 "@mogakko/browser-api": "workspace:*" + "@mogakko/date": "workspace:*" "@mogakko/http-fetch": "workspace:*" "@monorepo/hooks": "workspace:*" "@monorepo/ui": "workspace:*"