Skip to content

Commit

Permalink
Merge pull request #18 from mju-likelion/bugfix/today-calculation
Browse files Browse the repository at this point in the history
날짜 계산이 잘못되고 있던 문제 픽스
  • Loading branch information
ndaemy authored Aug 30, 2023
2 parents be42a99 + fa1f49f commit 1b1675f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"date-fns": "^2.30.0",
"lodash": "^4.17.21",
"nanoid": "^3.3.6",
"passport": "^0.6.0",
Expand Down
19 changes: 7 additions & 12 deletions src/api/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NotFoundException,
} from '@nestjs/common';
import { Room } from '@prisma/client';
import { add } from 'date-fns';
import uniq from 'lodash/uniq';
import { customAlphabet } from 'nanoid';

Expand Down Expand Up @@ -198,14 +199,9 @@ export class RoomsService {

const dates = createRoomDto.dates;
const firstDate = this.convertStringToDate(dates[0]);
const now = new Date();
const utc = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
const koreaTimeDiff = 9 * 60 * 60 * 1000;
const nowKoreanDate = new Date(utc + koreaTimeDiff);
const nowKoreanDate = add(new Date(), { hours: 9 });

const maxDate = new Date(
nowKoreanDate.setMonth(nowKoreanDate.getMonth() + 6)
);
const maxDate = add(nowKoreanDate, { months: 6 });
const maxDateString = `${maxDate.getFullYear()}-${(
'0' +
(maxDate.getMonth() + 1)
Expand All @@ -225,11 +221,10 @@ export class RoomsService {
errors.push('dates must be sorted');
}

if (
firstDate.getMonth() < nowKoreanDate.getMonth() ||
firstDate.getDate() < nowKoreanDate.getDate()
) {
errors.push('first date must be today no matter how early it is.');
if (firstDate < nowKoreanDate) {
errors.push(
'first date must be later than today no matter how early it is.'
);
}

if (sortedDates.at(-1) > maxDateString) {
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.20.2"

"@babel/runtime@^7.21.0":
version "7.22.11"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.11.tgz#7a9ba3bbe406ad6f9e8dd4da2ece453eb23a77a4"
integrity sha512-ee7jVNlWN09+KftVOu9n7S8gQzD/Z6hN/I8VBRXW4P1+Xe7kJGXMwu8vds4aGIMHZnNbdpSWCfZZtinytpcAvA==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.20.7", "@babel/template@^7.3.3":
version "7.21.9"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.21.9.tgz#bf8dad2859130ae46088a99c1f265394877446fb"
Expand Down Expand Up @@ -2143,6 +2150,13 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

date-fns@^2.30.0:
version "2.30.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0"
integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==
dependencies:
"@babel/runtime" "^7.21.0"

[email protected]:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand Down Expand Up @@ -4885,6 +4899,11 @@ reflect-metadata@^0.1.13:
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==

regenerator-runtime@^0.14.0:
version "0.14.0"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.14.0.tgz#5e19d68eb12d486f797e15a3c6a918f7cec5eb45"
integrity sha512-srw17NI0TUWHuGa5CFGGmhfNIeja30WMBfbslPNhf6JrqQlLN5gcrvig1oqPxiVaXb0oW0XRKtH6Nngs5lKCIA==

regexp.prototype.flags@^1.4.3:
version "1.5.0"
resolved "https://registry.yarnpkg.com/regexp.prototype.flags/-/regexp.prototype.flags-1.5.0.tgz#fe7ce25e7e4cca8db37b6634c8a2c7009199b9cb"
Expand Down

0 comments on commit 1b1675f

Please sign in to comment.