-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jeongwoo Park <[email protected]>
- Loading branch information
1 parent
65bfea4
commit 48c85ca
Showing
10 changed files
with
103 additions
and
34 deletions.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
export type RecruitmentStatusType = 'planned' | 'inProgress' | 'closed'; | ||
export type RecruitmentStatusType = 'Pending' | 'Ongoing' | 'Closed'; |
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,51 @@ | ||
import { getTimeStatus } from './compareTime'; | ||
|
||
describe('getTimeStatus 테스트', () => { | ||
beforeEach(() => { | ||
// 모든 테스트에서 시스템 시간을 동일한 날짜로 고정합니다. | ||
const mockCurrentDate = new Date('2024-08-21T00:00:00Z'); | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(mockCurrentDate); | ||
}); | ||
|
||
afterEach(() => { | ||
// 테스트 후 원래의 시스템 시간으로 복원합니다. | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('현재 날짜가 시작 날짜 이전이면 Pending을 반환해야 한다', () => { | ||
const result = getTimeStatus({ | ||
startDate: '2024-08-22T00:00:00Z', | ||
endDate: '2024-08-25T00:00:00Z', | ||
}); | ||
|
||
expect(result.status).toBe('Pending'); | ||
expect(result.isPending).toBe(true); | ||
expect(result.isOngoing).toBe(false); | ||
expect(result.isClosed).toBe(false); | ||
}); | ||
|
||
it('현재 날짜가 시작일과 종료일 사이에 있으면 Ongoing를 반환해야 한다', () => { | ||
const result = getTimeStatus({ | ||
startDate: '2024-08-20T00:00:00Z', | ||
endDate: '2024-08-23T00:00:00Z', | ||
}); | ||
|
||
expect(result.status).toBe('Ongoing'); | ||
expect(result.isPending).toBe(false); | ||
expect(result.isOngoing).toBe(true); | ||
expect(result.isClosed).toBe(false); | ||
}); | ||
|
||
it('현재 날짜가 종료 날짜 이후이면 Closed를 반환해야 한다', () => { | ||
const result = getTimeStatus({ | ||
startDate: '2024-08-18T00:00:00Z', | ||
endDate: '2024-08-20T00:00:00Z', | ||
}); | ||
|
||
expect(result.status).toBe('Closed'); | ||
expect(result.isPending).toBe(false); | ||
expect(result.isOngoing).toBe(false); | ||
expect(result.isClosed).toBe(true); | ||
}); | ||
}); |
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,30 @@ | ||
import { RecruitmentStatusType } from '@customTypes/recruitment'; | ||
import { getCleanDateString } from './formatDate'; | ||
|
||
interface GetRecruitmentStatusProps { | ||
startDate: string; | ||
endDate: string; | ||
} | ||
|
||
interface RecruitmentStatusObject { | ||
status: RecruitmentStatusType; | ||
isPending: boolean; | ||
isOngoing: boolean; | ||
isClosed: boolean; | ||
} | ||
|
||
export function getTimeStatus({ startDate, endDate }: GetRecruitmentStatusProps): RecruitmentStatusObject { | ||
const currentDate = getCleanDateString(); | ||
|
||
// TODO: 시간 지정 기능이 추가될 시 +24 로직은 사라져야 합니다. | ||
const endDatePlus24Hours = getCleanDateString(endDate); | ||
endDatePlus24Hours.setHours(endDatePlus24Hours.getHours() + 24); | ||
|
||
if (getCleanDateString(startDate) > currentDate) { | ||
return { status: 'Pending', isPending: true, isOngoing: false, isClosed: false }; | ||
} | ||
if (currentDate < endDatePlus24Hours) { | ||
return { status: 'Ongoing', isPending: false, isOngoing: true, isClosed: false }; | ||
} | ||
return { status: 'Closed', isPending: false, isOngoing: false, isClosed: true }; | ||
} |