Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: isomorphicDate 함수 생성 #215

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/jurumarble/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@emotion/is-prop-valid": "^1.2.1",
"@mogakko/browser-api": "workspace:*",
"@mogakko/date": "workspace:*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p5: date관련 코드까지 패키지로 분리할 필요가 있을까요?

"@mogakko/http-fetch": "workspace:*",
"@monorepo/hooks": "workspace:*",
"@monorepo/ui": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions apps/jurumarble/src/app/main/components/HotDrinkContainer.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<H2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use client';

import { getIsomorphicDate } from '@mogakko/date';
import Path from 'lib/Path';
import Image from 'next/image';
import { useRouter } from 'next/navigation';
import styled, { css } from 'styled-components';

import { useGetHotDrinkVoteService } from '../services/useGetHotDrinkVoteService';

const nowTime = getIsomorphicDate().getHours();

function HotDrinkVoteContainer() {
const router = useRouter();

Expand All @@ -16,8 +19,6 @@ function HotDrinkVoteContainer() {
}
const { voteId, voteTitle, drinkAImage, drinkBImage } = hotDrinkVote;

const nowTime = new Date().getHours();

return (
<>
<H2>
Expand Down
4 changes: 4 additions & 0 deletions packages/date/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
extends: ["mogakko"],
root: true,
};
1 change: 1 addition & 0 deletions packages/date/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src";
15 changes: 15 additions & 0 deletions packages/date/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions packages/date/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './isomorphicDate';
7 changes: 7 additions & 0 deletions packages/date/src/isomorphicDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @description 클라이언트, 서버에서 동일한 시간을 반환해주는 함수
*/
export const getIsomorphicDate = (timeZone = 'Asia/Seoul') => {
const time = new Date().toLocaleString('en-US', { timeZone });
return new Date(time);
};
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:*"
Expand Down
Loading