Skip to content

Commit 5c33216

Browse files
FeshchenkoF
andauthored
fix: wrong month array at the end of the month (#66)
Co-authored-by: F <f@MacBook-Pro-F.local>
1 parent 8f6534f commit 5c33216

File tree

8 files changed

+86
-50
lines changed

8 files changed

+86
-50
lines changed

.eslintignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 39 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Here is a quick guide to doing code contributions to the library.
2020
2121
5. Run all packages in dev mode:
2222

23-
> pnpm i
23+
> pnpm dev
2424
2525
6. If you've added a code that should be tested, ensure the test suite still passes.
2626

eslint.config.mjs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
2+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
3+
import reactHooks from "eslint-plugin-react-hooks";
4+
import simpleImportSort from "eslint-plugin-simple-import-sort";
5+
import prettier from "eslint-plugin-prettier";
6+
import tsParser from "@typescript-eslint/parser";
7+
import path from "node:path";
8+
import { fileURLToPath } from "node:url";
9+
import js from "@eslint/js";
10+
import { FlatCompat } from "@eslint/eslintrc";
11+
12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = path.dirname(__filename);
14+
const compat = new FlatCompat({
15+
baseDirectory: __dirname,
16+
recommendedConfig: js.configs.recommended,
17+
allConfig: js.configs.all
18+
});
19+
20+
export default [{
21+
ignores: ["node_modules", "dist", "rollup"],
22+
}, ...fixupConfigRules(compat.extends(
23+
"plugin:playwright/recommended",
24+
"plugin:react/recommended",
25+
"plugin:@typescript-eslint/recommended",
26+
"plugin:react-hooks/recommended",
27+
"prettier",
28+
)), {
29+
plugins: {
30+
"@typescript-eslint": fixupPluginRules(typescriptEslint),
31+
"react-hooks": fixupPluginRules(reactHooks),
32+
"simple-import-sort": simpleImportSort,
33+
prettier,
34+
},
35+
36+
languageOptions: {
37+
parser: tsParser,
38+
ecmaVersion: 2020,
39+
sourceType: "module",
40+
41+
parserOptions: {
42+
ecmaFeatures: {
43+
jsx: true,
44+
},
45+
},
46+
},
47+
48+
settings: {
49+
react: {
50+
pragma: "React",
51+
version: "detect",
52+
},
53+
},
54+
55+
rules: {
56+
"prettier/prettier": "error",
57+
"simple-import-sort/imports": "error",
58+
"simple-import-sort/exports": "error",
59+
"no-var": 0,
60+
},
61+
}, {
62+
files: ["**/*.test.ts", "**/*.test.tsx"],
63+
64+
rules: {
65+
"@typescript-eslint/ban-ts-comment": "off",
66+
},
67+
}];

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "datepicker",
3-
"version": "6.6.1",
3+
"version": "6.6.6",
44
"description": "The ultimate tool to create a date, range and time picker in your React applications.",
55
"scripts": {
66
"clean": "rimraf node_modules",
@@ -40,6 +40,7 @@
4040
},
4141
"homepage": "https://github.com/rehookify/datepicker#readme",
4242
"devDependencies": {
43+
"@eslint/compat": "^1.1.1",
4344
"@testing-library/react": "^16.0.0",
4445
"@typescript-eslint/eslint-plugin": "^7.15.0",
4546
"@typescript-eslint/parser": "^7.15.0",
@@ -62,6 +63,6 @@
6263
]
6364
},
6465
"engines": {
65-
"node": ">=16"
66+
"node": ">=18"
6667
}
6768
}

packages/datepicker/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rehookify/datepicker",
3-
"version": "6.6.5",
3+
"version": "6.6.6",
44
"description": "The ultimate tool to create a date, range and time picker in your React applications.",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.mjs",
@@ -83,6 +83,6 @@
8383
"access": "public"
8484
},
8585
"engines": {
86-
"node": ">=16"
86+
"node": ">=18"
8787
}
8888
}

packages/datepicker/src/utils/create-months.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DPDatesConfig, DPLocaleConfig, DPMonth } from '../types';
2-
import { formatMonthName, getDateParts, newDate } from './date';
2+
import { daysInMonth, formatMonthName, getDateParts, newDate } from './date';
33
import {
44
isAfterMaxMonth,
55
isBeforeMinMonth,
@@ -13,14 +13,16 @@ export var createMonths = (
1313
locale: DPLocaleConfig,
1414
{ minDate, maxDate }: DPDatesConfig,
1515
): DPMonth[] => {
16-
// 12 is a number of months in the year
1716
const { M, Y, D } = getDateParts(offsetDate);
1817
const { Y: nY, M: nM } = getDateParts(newDate());
1918

19+
// 12 is a number of months in the year
2020
return Array(12)
2121
.fill(0)
2222
.map((_, i) => {
23-
const $date = newDate(Y, i, D);
23+
// Prevent situation when previous month has less days than current March -> February
24+
const maxMonthDate = daysInMonth(newDate(Y, i, 1));
25+
const $date = newDate(Y, i, D > maxMonthDate ? maxMonthDate : D);
2426

2527
return {
2628
$date,

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)