Skip to content

Commit

Permalink
Use @wojtekmaj/date-utils package (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj authored Nov 10, 2019
1 parent 4a38abd commit b12d488
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 35 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
],
"license": "MIT",
"dependencies": {
"@wojtekmaj/date-utils": "^1.0.0",
"get-user-locale": "^1.2.0",
"make-event-props": "^1.1.0",
"merge-class-names": "^1.1.1",
Expand Down
8 changes: 3 additions & 5 deletions src/DateInput.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { polyfill } from 'react-lifecycles-compat';
import { getYear, getMonthHuman, getDate } from '@wojtekmaj/date-utils';

import Divider from './Divider';
import DayInput from './DateInput/DayInput';
Expand All @@ -12,10 +13,7 @@ import NativeInput from './DateInput/NativeInput';
import { getFormatter } from './shared/dateFormatter';
import {
getBegin,
getDay,
getEnd,
getMonth,
getYear,
} from './shared/dates';
import { isMaxDate, isMinDate } from './shared/propTypes';
import { between } from './shared/utils';
Expand Down Expand Up @@ -200,8 +198,8 @@ export default class DateInput extends PureComponent {
) {
if (nextValue) {
nextState.year = getYear(nextValue);
nextState.month = getMonth(nextValue);
nextState.day = getDay(nextValue);
nextState.month = getMonthHuman(nextValue);
nextState.day = getDate(nextValue);
} else {
nextState.year = null;
nextState.month = null;
Expand Down
16 changes: 8 additions & 8 deletions src/DateInput/DayInput.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
getYear,
getMonthHuman,
getDate,
getDaysInMonth,
} from '@wojtekmaj/date-utils';

import Input from './Input';

import {
getDay,
getDaysInMonth,
getMonth,
getYear,
} from '../shared/dates';
import { isMaxDate, isMinDate } from '../shared/propTypes';
import { min, max } from '../shared/utils';

Expand All @@ -29,11 +29,11 @@ export default function DayInput({

const maxDay = min(
currentMonthMaxDays,
maxDate && year === getYear(maxDate) && month === getMonth(maxDate) && getDay(maxDate),
maxDate && year === getYear(maxDate) && month === getMonthHuman(maxDate) && getDate(maxDate),
);

const minDay = max(
1, minDate && year === getYear(minDate) && month === getMonth(minDate) && getDay(minDate),
1, minDate && year === getYear(minDate) && month === getMonthHuman(minDate) && getDate(minDate),
);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/DateInput/MonthInput.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { getYear, getMonthHuman } from '@wojtekmaj/date-utils';

import Input from './Input';

import { getMonth, getYear } from '../shared/dates';
import { isMaxDate, isMinDate } from '../shared/propTypes';
import { min, max } from '../shared/utils';

Expand All @@ -13,8 +13,8 @@ export default function MonthInput({
year,
...otherProps
}) {
const maxMonth = min(12, maxDate && year === getYear(maxDate) && getMonth(maxDate));
const minMonth = max(1, minDate && year === getYear(minDate) && getMonth(minDate));
const maxMonth = min(12, maxDate && year === getYear(maxDate) && getMonthHuman(maxDate));
const minMonth = max(1, minDate && year === getYear(minDate) && getMonthHuman(minDate));

return (
<Input
Expand Down
8 changes: 4 additions & 4 deletions src/DateInput/MonthSelect.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import mergeClassNames from 'merge-class-names';
import { getYear, getMonthHuman } from '@wojtekmaj/date-utils';

import { getMonth, getYear } from '../shared/dates';
import { formatMonth, formatShortMonth } from '../shared/dateFormatter';
import { isMaxDate, isMinDate } from '../shared/propTypes';
import { min, max } from '../shared/utils';
Expand All @@ -20,8 +20,8 @@ export default function MonthSelect({
year,
...otherProps
}) {
const maxMonth = min(12, maxDate && year === getYear(maxDate) && getMonth(maxDate));
const minMonth = max(1, minDate && year === getYear(minDate) && getMonth(minDate));
const maxMonth = min(12, maxDate && year === getYear(maxDate) && getMonthHuman(maxDate));
const minMonth = max(1, minDate && year === getYear(minDate) && getMonthHuman(minDate));
const dates = [...Array(12)].map((el, index) => new Date(2019, index, 1));
const name = 'month';
const formatter = short ? formatShortMonth : formatMonth;
Expand All @@ -48,7 +48,7 @@ export default function MonthSelect({
</option>
)}
{dates.map((date) => {
const month = getMonth(date);
const month = getMonthHuman(date);
const disabled = month < minMonth || month > maxMonth;

return (
Expand Down
6 changes: 3 additions & 3 deletions src/DateInput/NativeInput.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';

import {
getYear,
getISOLocalDate,
getISOLocalMonth,
getYear,
} from '../shared/dates';
} from '@wojtekmaj/date-utils';

import { isMaxDate, isMinDate, isValueType } from '../shared/propTypes';

export default function NativeInput({
Expand Down
2 changes: 1 addition & 1 deletion src/DateInput/YearInput.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { getYear } from '@wojtekmaj/date-utils';

import Input from './Input';

import { getYear } from '../shared/dates';
import { isMaxDate, isMinDate, isValueType } from '../shared/propTypes';
import { max, min } from '../shared/utils';

Expand Down
7 changes: 0 additions & 7 deletions src/shared/dates.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
export {
getYear,
getMonth,
getMonthIndex,
getDay,
getDaysInMonth,
getBegin,
getEnd,
getISOLocalMonth,
getISOLocalDate,
} from 'react-calendar/dist/shared/dates';
3 changes: 1 addition & 2 deletions test/ValidityOptions.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { getISOLocalDate } from '../src/shared/dates';
import { getISOLocalDate } from '@wojtekmaj/date-utils';

export default function ValidityOptions({
maxDate,
Expand Down
3 changes: 1 addition & 2 deletions test/ValueOptions.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import { getISOLocalDate } from '../src/shared/dates';
import { getISOLocalDate } from '@wojtekmaj/date-utils';

export default function ValueOptions({
setState,
Expand Down
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"license": "MIT",
"dependencies": {
"@wojtekmaj/date-utils": "^1.0.0",
"prop-types": "^15.6.0",
"react": "^16.5.0",
"react-date-picker": "latest",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,11 @@
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-12.0.12.tgz#45dd1d0638e8c8f153e87d296907659296873916"
integrity sha512-SOhuU4wNBxhhTHxYaiG5NY4HBhDIDnJF60GU+2LqHAdKKer86//e4yg69aENCtQ04n0ovz+tq2YPME5t5yp4pw==

"@wojtekmaj/date-utils@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@wojtekmaj/date-utils/-/date-utils-1.0.0.tgz#97aebf5ab317cf40d56492642f921480d4f89342"
integrity sha512-tHzSlWCmb1GjxjiPRTju7i2bQigYriFDmCpaf1dC4SebFRjhBiuRpIxy5oI3b3ZMg9OzqGnApdZJrlYSwEUJAg==

abab@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.0.tgz#aba0ab4c5eee2d4c79d3487d85450fb2376ebb0f"
Expand Down

0 comments on commit b12d488

Please sign in to comment.