-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Refactor] date-fns 라이브러리 제거 #469
Open
lydiacho
wants to merge
13
commits into
develop
Choose a base branch
from
refactor/#458_remove-datefns
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e83394e
feat: isBefore, isAfter 함수 구현
lydiacho 3a67265
feat: differenceInSeconds 함수 구현
lydiacho b98d32b
feat: subMinutes 함수 구현
lydiacho 4f16fb8
feat: format 함수 구현
lydiacho 63afc4a
remove: Intl 덜어내기
lydiacho 7374bdb
feat: string -> Date 형변환 처리 추가
lydiacho ceb709b
remove: test 용 파일 삭제
lydiacho e62d6d6
remove: date-fns 라이브러리 삭제
lydiacho 2075ced
feat: EEEE RegExp 추가
lydiacho ac856e3
fix: toDate 함수 분리
lydiacho 9074cfc
fix: 요일 인덱스 버그 픽스
lydiacho 215b287
fix: toDate 적용 및 throw Error -> console error로 수정
lydiacho ab2d87d
fix: throw Error 코드 복구
lydiacho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const isBefore = (date: Date | string, dateToCompare: Date | string): boolean => { | ||
if (typeof date === 'string') date = new Date(date); | ||
if (typeof dateToCompare === 'string') dateToCompare = new Date(dateToCompare); | ||
return date.getTime() < dateToCompare.getTime(); | ||
}; | ||
|
||
export const isAfter = (date: Date | string, dateToCompare: Date | string): boolean => { | ||
if (typeof date === 'string') date = new Date(date); | ||
if (typeof dateToCompare === 'string') dateToCompare = new Date(dateToCompare); | ||
return date.getTime() > dateToCompare.getTime(); | ||
}; | ||
|
||
export const differenceInSeconds = (laterDate: Date | string, earlierDate: Date | string): number => { | ||
if (typeof laterDate === 'string') laterDate = new Date(laterDate); | ||
if (typeof earlierDate === 'string') earlierDate = new Date(earlierDate); | ||
return Math.floor((laterDate.getTime() - earlierDate.getTime()) / 1000); | ||
}; | ||
|
||
export const subMinutes = (date: Date | string, amount: number): Date => { | ||
if (typeof date === 'string') date = new Date(date); | ||
const newDate = new Date(); | ||
newDate.setTime(date.getTime() - amount * 60 * 1000); | ||
return newDate; | ||
}; | ||
lydiacho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export const format = (date: Date | string, formatStr: string): string => { | ||
if (typeof date === 'string') date = new Date(date); | ||
const days = ['월', '화', '수', '목', '금', '토', '일']; | ||
const formatter: { [key: string]: string } = { | ||
M: (date.getMonth() + 1).toString(), | ||
dd: date.getDate().toString().padStart(2, '0'), | ||
E: days[date.getDay() - 1], | ||
EEEE: days[date.getDay() - 1] + '요일', | ||
lydiacho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
aaa: date.getHours() < 12 ? '오전' : '오후', | ||
HH: date.getHours().toString().padStart(2, '0'), | ||
hh: (date.getHours() % 12 || 12).toString().padStart(2, '0'), | ||
mm: date.getMinutes().toString().padStart(2, '0'), | ||
}; | ||
|
||
return formatStr.replace(/M|dd|E|EEE|aaa|HH|hh|mm/g, (substr) => formatter[substr]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
계속 반복되니
따로 분리해줘도 좋을 거 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가로 유효하지 않은 date 값이 들어왔을 때 예외 처리도 toDate에서 같이 해주면 좋을 거 같아요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용자가 확인해야할 내용은 아니니 페이지 터뜨리지 않게 throw Error말고 console error로 처리했어요.
어떠신가요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
차피 서버에서 데이터 받아오는 거기 때문에 사용자에게 에러를 보게될 일은 없을 거 같아요
코드를 유지보수 하면서 서버에 받아온 데이터를 저희가 처리하는 과정에서 에러가 발생될 수 있는데 이때 console로만 찍으면 이를 인지하지 못하고 넘어갈 수 있겠다는 우려가 되네요
그래서 throw가 더 좋을 거 같단 생각입니다 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 잘 이해하지 못했는데, 왜 사용자가 에러를 보지 못하게 되나요??
에러가 throw 되면 저희 구현상 에러페이지로 빠지게 되는 상태인데, 만약 사용자가 접속했을 때 서버로 받아온 날짜 데이터에 하나라도 비정상적인 값 (혹은 undefined)가 들어오면 에러페이지로 이동하게 되는것 아닌가요??
실제로 지금 비정상적인 서버 환경에서 throw Error로 처리했더니 아예 무조건 에러페이지로만 가버려서 UI를 보면서 개발을 할 수가 없더라구요 ㅠ ㅠ 그래서 저는 최소한의 UI는 확인해볼 수 있게 콘솔로만 남겼던겁니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서버에서 잘못된 값을 보내면 안 되니까요! 정상적인 데이터만 서버에서 넘겨줄 테니 에러가 발생하지 않을 거예요
하나, 서버에서 잘못된 값을 보냈다고 해도, 이상하게 처리되어서 잘못된 숫자가 찍히게 되어 사용자에게 혼동을 주기 보다 차라리 에러 터트리는 게 더 나을 거 같다는 생각이에요 :)
이건 사실 이 뿐만 아니라 어느 에러가 발생해도 다 똑같아요
에러가 발생할 시 500 페이지로 이동하도록 공통적으로 처리해놔서 그런데요
개발하는 동안은 이를 잠시 주석 처리 하는 등 하면 될 거 같다는 생각입니다~
근데 뭐,, 중요한 거 아니니까 편한대로 해주세여~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아아 그부분은 저도 동의해요 전 아예 에러페이지로 이동 안한다는 의미라고 이해했어요
그럼 throw로 바꾸고 주석처리해둘게요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인했습니다! 고생하셨어요 :)