-
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.
- Loading branch information
Showing
59 changed files
with
1,230 additions
and
75 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,27 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
}, | ||
extends: ['@croquiscom/eslint-config/requiring-type-checking'], | ||
ignorePatterns: ['.eslintrc.cjs', 'lib'], | ||
parserOptions: { | ||
project: ['./tsconfig.json'], | ||
}, | ||
rules: { | ||
'import/export': 'off', | ||
'@typescript-eslint/no-unsafe-call': 'off', | ||
'@typescript-eslint/no-unsafe-member-access': 'off', | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
'@typescript-eslint/no-unsafe-return': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-floating-promises': 'off', | ||
'@typescript-eslint/restrict-template-expressions': 'off', | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: { | ||
project: __dirname, | ||
}, | ||
}, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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 @@ | ||
{"type":"commonjs"} |
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,2 +1,2 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2019: IYearHolidays; |
File renamed without changes.
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,2 +1,2 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2020: IYearHolidays; |
File renamed without changes.
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,2 +1,2 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2021: IYearHolidays; |
File renamed without changes.
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,2 +1,2 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2022: IYearHolidays; |
File renamed without changes.
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,2 +1,2 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2023: IYearHolidays; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
lib/year_holidays/fallback.d.ts → lib/cjs/year_holidays/fallback.d.ts
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,3 +1,3 @@ | ||
import { IYearHolidays } from './types'; | ||
import { IYearHolidays } from './types.js'; | ||
declare const HOLIDAYS_FALLBACK: IYearHolidays; | ||
export { HOLIDAYS_FALLBACK }; |
File renamed without changes.
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,3 @@ | ||
import { IYearHolidays } from './types.js'; | ||
export declare const KOREAN_HOLIDAYS: Record<number, IYearHolidays | undefined>; | ||
export { HOLIDAYS_FALLBACK } from './fallback.js'; |
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,18 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.HOLIDAYS_FALLBACK = exports.KOREAN_HOLIDAYS = void 0; | ||
var _2019_js_1 = require("./2019.js"); | ||
var _2020_js_1 = require("./2020.js"); | ||
var _2021_js_1 = require("./2021.js"); | ||
var _2022_js_1 = require("./2022.js"); | ||
var _2023_js_1 = require("./2023.js"); | ||
// 토, 일요일 정보는 포함하지 않음 | ||
exports.KOREAN_HOLIDAYS = { | ||
2019: _2019_js_1.HOLIDAYS_2019, | ||
2020: _2020_js_1.HOLIDAYS_2020, | ||
2021: _2021_js_1.HOLIDAYS_2021, | ||
2022: _2022_js_1.HOLIDAYS_2022, | ||
2023: _2023_js_1.HOLIDAYS_2023, | ||
}; | ||
var fallback_js_1 = require("./fallback.js"); | ||
Object.defineProperty(exports, "HOLIDAYS_FALLBACK", { enumerable: true, get: function () { return fallback_js_1.HOLIDAYS_FALLBACK; } }); |
File renamed without changes.
File renamed without changes.
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,34 @@ | ||
/** | ||
* 휴일 여부를 반환합니다. | ||
* @param date 살펴볼 날짜 | ||
* @returns 휴일 여부 | ||
*/ | ||
export declare function isHoliday(date: Date): boolean; | ||
/** | ||
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 후를 반환합니다. | ||
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자) | ||
* @param days_after n일 후 | ||
* @returns 다음 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export declare function getNextKoreanBusinessDayYmd(day_ymd: number, days_after: number): number; | ||
/** | ||
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 전을 반환합니다. | ||
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자) | ||
* @param days_after n일 전 | ||
* @returns 이전 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export declare function getPreviousKoreanBusinessDayYmd(day_ymd: number, days_before: number): number; | ||
/** | ||
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 후를 반환합니다. | ||
* @param date 기준일(UTC 시각) | ||
* @param days_after n일 후 | ||
* @returns 다음 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export declare function getNextKoreanBusinessDayYmdByUtcDate(date: Date, days_after: number): number; | ||
/** | ||
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 전을 반환합니다. | ||
* @param date 기준일(UTC 시각) | ||
* @param days_after n일 전 | ||
* @returns 이전 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export declare function getPreviousKoreanBusinessDayYmdByUtcDate(date: Date, days_before: number): number; |
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,114 @@ | ||
import { HOLIDAYS_FALLBACK, KOREAN_HOLIDAYS } from './year_holidays/index.js'; | ||
function getYmdByDate(date) { | ||
return { | ||
day: date.getDate(), | ||
month: date.getMonth() + 1, | ||
year: date.getFullYear(), | ||
}; | ||
} | ||
function getDateFromDayYmd(day_ymd) { | ||
if (!/^20[0-9][0-9](0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/.test(String(day_ymd))) { | ||
throw new Error("invalid day_ymd: ".concat(day_ymd)); | ||
} | ||
var day_m = "0".concat(Math.floor((day_ymd / 100) % 100)).slice(-2); | ||
var day_d = "0".concat(Math.floor(day_ymd % 100)).slice(-2); | ||
return new Date("".concat(Math.floor(day_ymd / 10000), "-").concat(day_m, "-").concat(day_d, "T09:00:00+09:00")); | ||
} | ||
function getBusinessDay(_a) { | ||
var _b; | ||
var date = _a.date, days_to_go = _a.days_to_go, set_date_increased = _a.set_date_increased; | ||
if (days_to_go < 1) { | ||
throw new Error("second parameter value should be positive value"); | ||
} | ||
while (days_to_go) { | ||
date.setDate(date.getDate() + (set_date_increased ? 1 : -1)); | ||
var day = date.getDay(); | ||
if (day === 0 || day === 6) { | ||
continue; | ||
} | ||
var ymd = getYmdByDate(date); | ||
var holiday_of_year = (_b = KOREAN_HOLIDAYS[ymd.year]) !== null && _b !== void 0 ? _b : HOLIDAYS_FALLBACK; | ||
var holiday_of_month = holiday_of_year[ymd.month]; | ||
if (!holiday_of_month) { | ||
throw new Error("month ".concat(ymd.month, " data not exists")); | ||
} | ||
if (holiday_of_month[ymd.day]) { | ||
continue; | ||
} | ||
days_to_go--; | ||
} | ||
var result = getYmdByDate(date); | ||
return result.year * 10000 + result.month * 100 + result.day; | ||
} | ||
/** | ||
* 휴일 여부를 반환합니다. | ||
* @param date 살펴볼 날짜 | ||
* @returns 휴일 여부 | ||
*/ | ||
export function isHoliday(date) { | ||
var _a; | ||
date = new Date(date); | ||
date.setUTCHours(date.getUTCHours() + 9); | ||
var day = date.getDay(); | ||
var ymd = getYmdByDate(date); | ||
var holiday_of_year = (_a = KOREAN_HOLIDAYS[ymd.year]) !== null && _a !== void 0 ? _a : HOLIDAYS_FALLBACK; | ||
var holiday_of_month = holiday_of_year[ymd.month]; | ||
var result = (holiday_of_month === null || holiday_of_month === void 0 ? void 0 : holiday_of_month[ymd.day]) !== undefined; | ||
return day === 0 || day === 6 || result; | ||
} | ||
/** | ||
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 후를 반환합니다. | ||
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자) | ||
* @param days_after n일 후 | ||
* @returns 다음 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export function getNextKoreanBusinessDayYmd(day_ymd, days_after) { | ||
return getBusinessDay({ | ||
date: getDateFromDayYmd(day_ymd), | ||
days_to_go: days_after, | ||
set_date_increased: true, | ||
}); | ||
} | ||
/** | ||
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 전을 반환합니다. | ||
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자) | ||
* @param days_after n일 전 | ||
* @returns 이전 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export function getPreviousKoreanBusinessDayYmd(day_ymd, days_before) { | ||
return getBusinessDay({ | ||
date: getDateFromDayYmd(day_ymd), | ||
days_to_go: days_before, | ||
set_date_increased: false, | ||
}); | ||
} | ||
/** | ||
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 후를 반환합니다. | ||
* @param date 기준일(UTC 시각) | ||
* @param days_after n일 후 | ||
* @returns 다음 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export function getNextKoreanBusinessDayYmdByUtcDate(date, days_after) { | ||
date = new Date(date); | ||
date.setUTCHours(date.getUTCHours() + 9); | ||
return getBusinessDay({ | ||
date: date, | ||
days_to_go: days_after, | ||
set_date_increased: true, | ||
}); | ||
} | ||
/** | ||
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 전을 반환합니다. | ||
* @param date 기준일(UTC 시각) | ||
* @param days_after n일 전 | ||
* @returns 이전 영업일(YYYYMMDD 형태의 숫자) | ||
*/ | ||
export function getPreviousKoreanBusinessDayYmdByUtcDate(date, days_before) { | ||
date = new Date(date); | ||
date.setUTCHours(date.getUTCHours() + 9); | ||
return getBusinessDay({ | ||
date: date, | ||
days_to_go: days_before, | ||
set_date_increased: false, | ||
}); | ||
} |
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,2 @@ | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2019: IYearHolidays; |
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,39 @@ | ||
export var HOLIDAYS_2019 = { | ||
1: { | ||
1: true, // 신정 | ||
}, | ||
2: { | ||
4: true, | ||
5: true, | ||
6: true, // 설날 연휴 | ||
}, | ||
3: { | ||
1: true, // 삼일절 | ||
}, | ||
4: {}, | ||
5: { | ||
5: true, | ||
6: true, | ||
12: true, // 부처님 오신날 | ||
}, | ||
6: { | ||
6: true, // 현충일 | ||
}, | ||
7: {}, | ||
8: { | ||
15: true, // 광복절 | ||
}, | ||
9: { | ||
12: true, | ||
13: true, | ||
14: true, // 추석 연휴 | ||
}, | ||
10: { | ||
3: true, | ||
9: true, // 한글날 | ||
}, | ||
11: {}, | ||
12: { | ||
25: 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,2 @@ | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2020: IYearHolidays; |
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,42 @@ | ||
export var HOLIDAYS_2020 = { | ||
1: { | ||
1: true, | ||
24: true, | ||
25: true, | ||
26: true, | ||
27: true, // 대체 휴일 | ||
}, | ||
2: {}, | ||
3: { | ||
1: true, // 삼일절 | ||
}, | ||
4: { | ||
15: true, | ||
30: true, // 부처님 오신날 | ||
}, | ||
5: { | ||
1: true, | ||
5: true, // 어린이날 | ||
}, | ||
6: { | ||
6: true, // 현충일 | ||
}, | ||
7: {}, | ||
8: { | ||
15: true, | ||
17: true, // 광복절 대체 임시공휴일 | ||
}, | ||
9: { | ||
30: true, // 추석 연휴 | ||
}, | ||
10: { | ||
1: true, | ||
2: true, | ||
3: true, | ||
9: true, // 한글날 | ||
}, | ||
11: {}, | ||
12: { | ||
25: 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,2 @@ | ||
import { IYearHolidays } from './types.js'; | ||
export declare const HOLIDAYS_2021: IYearHolidays; |
Oops, something went wrong.