-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 날짜 및 시간 유틸 함수 구현 #17
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,31 @@ | ||
| //"YYYY-MM-DD" 형식의 한국식 날짜 문자열 | ||
| export function formatDate(d: Date): string { | ||
| return d | ||
| .toLocaleDateString("ko-KR", { | ||
| year: "numeric", | ||
| month: "2-digit", | ||
| day: "2-digit", | ||
| }) | ||
| .replace(/\.\s?/g, "-") | ||
| .slice(0, 10); | ||
| } | ||
| //"HH:MM" 형식의 24시간제 시간 문자열로 변환 | ||
| export function formatTime(d: Date): string { | ||
| return d.toLocaleTimeString("ko-KR", { | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| hour12: false, | ||
| }); | ||
| } | ||
| // 시작 시간 + workhour 기준으로 endTime까지 포함한 시간 범위 문자열 | ||
| export function formatTimeRange(startsAt: string, workhour: number): string { | ||
| const start = new Date(startsAt); | ||
| const end = new Date(start.getTime() + workhour * 3600000); | ||
|
||
| return `${formatDate(start)} ${formatTime(start)}~${formatTime(end)} (${workhour}시간)`; | ||
| } | ||
| // 시작 시간과 종료 시간을 기준으로 과거 여부 판단 | ||
| export function isPastDate(startsAt: string, workhour: number): boolean { | ||
| const start = new Date(startsAt); | ||
| const end = new Date(start.getTime() + workhour * 3600000); | ||
| return end.getTime() < Date.now(); | ||
| } | ||
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.
그냥 단순히 궁금한 부분입니다만,
왜
startAt이 아니라startsAt인가요..! 😅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.
그리고 입력받는
startsAt이string타입이라면전달 받아야 하는 특정 형태가 있을까요? 🤔 (ex:
YYYY-MM-DD HH:mm등)있다면 JSDoc을 사용해서 어떤 형태로 전달 받아야 하는지에 대한 설명이 포함되면 좋겠어요! 👍
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.
api 리스폰스가
startsAt으로 오는 것 같아서startsAt으로 지정하기는 했습니다..!😊