Skip to content

Commit

Permalink
fix: wrong month array at the end of the month (#66)
Browse files Browse the repository at this point in the history
Co-authored-by: F <[email protected]>
  • Loading branch information
Feshchenko and F authored Jul 29, 2024
1 parent 8f6534f commit 5c33216
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

39 changes: 0 additions & 39 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Here is a quick guide to doing code contributions to the library.
5. Run all packages in dev mode:

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

Expand Down
67 changes: 67 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import reactHooks from "eslint-plugin-react-hooks";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import prettier from "eslint-plugin-prettier";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["node_modules", "dist", "rollup"],
}, ...fixupConfigRules(compat.extends(
"plugin:playwright/recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"prettier",
)), {
plugins: {
"@typescript-eslint": fixupPluginRules(typescriptEslint),
"react-hooks": fixupPluginRules(reactHooks),
"simple-import-sort": simpleImportSort,
prettier,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 2020,
sourceType: "module",

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
pragma: "React",
version: "detect",
},
},

rules: {
"prettier/prettier": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-var": 0,
},
}, {
files: ["**/*.test.ts", "**/*.test.tsx"],

rules: {
"@typescript-eslint/ban-ts-comment": "off",
},
}];
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datepicker",
"version": "6.6.1",
"version": "6.6.6",
"description": "The ultimate tool to create a date, range and time picker in your React applications.",
"scripts": {
"clean": "rimraf node_modules",
Expand Down Expand Up @@ -40,6 +40,7 @@
},
"homepage": "https://github.com/rehookify/datepicker#readme",
"devDependencies": {
"@eslint/compat": "^1.1.1",
"@testing-library/react": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^7.15.0",
"@typescript-eslint/parser": "^7.15.0",
Expand All @@ -62,6 +63,6 @@
]
},
"engines": {
"node": ">=16"
"node": ">=18"
}
}
4 changes: 2 additions & 2 deletions packages/datepicker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rehookify/datepicker",
"version": "6.6.5",
"version": "6.6.6",
"description": "The ultimate tool to create a date, range and time picker in your React applications.",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.mjs",
Expand Down Expand Up @@ -83,6 +83,6 @@
"access": "public"
},
"engines": {
"node": ">=16"
"node": ">=18"
}
}
8 changes: 5 additions & 3 deletions packages/datepicker/src/utils/create-months.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DPDatesConfig, DPLocaleConfig, DPMonth } from '../types';
import { formatMonthName, getDateParts, newDate } from './date';
import { daysInMonth, formatMonthName, getDateParts, newDate } from './date';
import {
isAfterMaxMonth,
isBeforeMinMonth,
Expand All @@ -13,14 +13,16 @@ export var createMonths = (
locale: DPLocaleConfig,
{ minDate, maxDate }: DPDatesConfig,
): DPMonth[] => {
// 12 is a number of months in the year
const { M, Y, D } = getDateParts(offsetDate);
const { Y: nY, M: nM } = getDateParts(newDate());

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

return {
$date,
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c33216

Please sign in to comment.