-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE] feat: 주차권 설정에서 현재 시간보다 이전 시간으로 설정하는 것을 방지한다. (#189)
- Loading branch information
Showing
5 changed files
with
124 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getFormalDateBy } from '../functions/date'; | ||
|
||
describe('분 단위 bound 테스트', () => { | ||
it('0분 일 때, 가장 빠른 30분으로 적용이 된다.', () => { | ||
expect(getFormalDateBy(new Date('2023-04-21T12:00:00')).getTime()).toEqual( | ||
new Date('2023-04-21T12:30:00').getTime(), | ||
); | ||
}); | ||
it('1분 일 때, 가장 빠른 30분으로 적용이 된다.', () => { | ||
expect(getFormalDateBy(new Date('2023-04-21T12:01:00')).getTime()).toEqual( | ||
new Date('2023-04-21T12:30:00').getTime(), | ||
); | ||
}); | ||
it('29분 일 때, 가장 빠른 30분으로 적용이 된다.', () => { | ||
expect(getFormalDateBy(new Date('2023-04-21T12:29:59')).getTime()).toEqual( | ||
new Date('2023-04-21T12:30:00').getTime(), | ||
); | ||
}); | ||
it('31분 일 때, 가장 빠른 정각으로 적용이 된다.', () => { | ||
expect(getFormalDateBy(new Date('2023-04-21T12:31:00')).getTime()).toEqual( | ||
new Date('2023-04-21T13:00:00').getTime(), | ||
); | ||
}); | ||
it('59분 일 때, 가장 빠른 정각으로 적용이 된다.', () => { | ||
expect(getFormalDateBy(new Date('2023-04-21T12:59:59')).getTime()).toEqual( | ||
new Date('2023-04-21T13:00:00').getTime(), | ||
); | ||
}); | ||
}); | ||
|
||
describe('년, 월 단위 bound 테스트', () => { | ||
it('년,월,일의 경계 일때, 년, 월, 일이 제대로 넘어가는지', () => { | ||
expect(getFormalDateBy(new Date('2023-12-31T23:59:00')).getTime()).toEqual( | ||
new Date('2024-01-01T00:00:00').getTime(), | ||
); | ||
}); | ||
|
||
it('월, 일의 경계일 때, 월, 일이 제대로 넘어가는지', () => { | ||
expect(getFormalDateBy(new Date('2023-11-30T23:59:00')).getTime()).toEqual( | ||
new Date('2023-12-01T00:00:00').getTime(), | ||
); | ||
}); | ||
}); |
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,23 @@ | ||
export const getFormalDateBy = (time: Date) => { | ||
const currentHour = time.getHours(); | ||
const currentMin = time.getMinutes(); | ||
const returnDate = new Date(time); | ||
returnDate.setMilliseconds(0); | ||
returnDate.setSeconds(0); | ||
|
||
if (currentMin >= 0 && currentMin <= 30) { | ||
const gap = 30 - currentMin; | ||
return new Date(returnDate.getTime() + 60000 * gap); | ||
} | ||
|
||
if (currentMin >= 30 && currentMin < 60) { | ||
const gap = 60 - currentMin; | ||
return new Date(returnDate.getTime() + 60000 * gap); | ||
} | ||
|
||
return returnDate; | ||
}; | ||
|
||
export const isPastTime = (date: Date) => { | ||
return Date.now() > date.getTime(); | ||
}; |
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