Skip to content

feat(*): update date-fns #1235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gemini/calendar.gemini.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import startOfDay from 'date-fns/start_of_day';
import addDays from 'date-fns/add_days';
import subtractDays from 'date-fns/sub_days';
import getTime from 'date-fns/get_time';
import startOfDay from 'date-fns/startOfDay';
import addDays from 'date-fns/addDays';
import subtractDays from 'date-fns/subDays';
import getTime from 'date-fns/getTime';

import Calendar from '../src/calendar';
import GeminiBox from '../gemini-utils/gemini-box/gemini-box';
Expand Down
54 changes: 31 additions & 23 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"bezier-easing": "2.1.0",
"cn-decorator": "^2.1.0",
"core-js": "2.5.5",
"date-fns": "1.29.0",
"date-fns": "2.16.1",
"deprecated-decorator": "0.1.6",
"inputmask-core": "2.2.0",
"libphonenumber-js": "1.0.24",
Expand Down
12 changes: 7 additions & 5 deletions src/calendar-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
```

```jsx
const formatDate = require('date-fns/format');
import { format as formatDate } from 'date-fns';

<div>
{
['s', 'm', 'l', 'xl'].map(size => (
<div className='row' key={ size }>
<CalendarInput size={ size } placeholder={ formatDate(new Date(), 'DD.MM.YYYY') } width='available' />
<CalendarInput size={ size } placeholder={ formatDate(new Date(), 'dd.MM.yyyy') } width='available' />
</div>
))
}
Expand Down Expand Up @@ -81,8 +81,10 @@ const IconOk = require('../../src/icon/ui/ok').default;

С отображением текущей даты
```jsx
const addDays = require('date-fns/add_days');
const formatDate = require('date-fns/format');
import {
addDays,
format as formatDate
} from 'date-fns';

const currentDate = new Date();

Expand All @@ -94,7 +96,7 @@ const calendar = {
<CalendarInput
size='m'
calendar={ calendar }
defaultValue={ formatDate(addDays(currentDate, 2), 'DD.MM.YYYY') }
defaultValue={ formatDate(addDays(currentDate, 2), 'dd.MM.yyyy') }
mobileMode='popup'
/>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/calendar-input/calendar-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,20 +402,20 @@ describe('calendar-input', () => {

describe('calendar utils', () => {
it('should change format of a date', () => {
const result = calendarUtils.changeDateFormat('2012-11-10', 'YYYY-MM-DD', 'DD.MM.YYYY');
const result = calendarUtils.changeDateFormat('2012-11-10', 'yyyy-MM-dd', 'dd.MM.yyyy');

expect(result).toBe('10.11.2012');
});

it('should return start of month', () => {
const result = new Date(calendarUtils.calculateMonth('2012-11-10', 'YYYY-MM-DD'));
const result = new Date(calendarUtils.calculateMonth('2012-11-10', 'yyyy-MM-dd'));

expect(result.getMonth() + 1).toBe(11); // getMonth is zero based
expect(result.getFullYear()).toBe(2012);
});

it('should return current month if not valid value given', () => {
const result = new Date(calendarUtils.calculateMonth('foo', 'YYYY-MM-DD'));
const result = new Date(calendarUtils.calculateMonth('foo', 'yyyy-MM-dd'));
const now = new Date();

expect(result.getMonth()).toBe(now.getMonth());
Expand All @@ -425,7 +425,7 @@ describe('calendar-input', () => {
it('should return earlierLimit month if it after given date', () => {
const result = new Date(calendarUtils.calculateMonth(
'2012-11-10',
'YYYY-MM-DD',
'yyyy-MM-dd',
(new Date(2013, 8, 10).getTime()),
));

Expand All @@ -436,7 +436,7 @@ describe('calendar-input', () => {
it('should return laterLimit month if it before given date', () => {
const result = new Date(calendarUtils.calculateMonth(
'2012-11-10',
'YYYY-MM-DD',
'yyyy-MM-dd',
(new Date(2011, 8, 10).getTime()),
(new Date(2011, 9, 10).getTime()),
));
Expand All @@ -448,7 +448,7 @@ describe('calendar-input', () => {
it('should return start of month if earlier and later limit given, but value is between them', () => {
const result = new Date(calendarUtils.calculateMonth(
'2012-11-10',
'YYYY-MM-DD',
'yyyy-MM-dd',
(new Date(2011, 8, 10).getTime()),
(new Date(2014, 9, 10).getTime()),
));
Expand Down
10 changes: 5 additions & 5 deletions src/calendar-input/calendar-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import {
import performance from '../performance';

/**
* NB: В нативном календаре нельзя менять формат даты. Приемлем только YYYY-MM-DD формат.
* NB: В нативном календаре нельзя менять формат даты. Приемлем только yyyy-MM-dd формат.
* https://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.value
* https://tools.ietf.org/html/rfc3339#section-5.6
*/
const CUSTOM_DATE_FORMAT = 'DD.MM.YYYY';
const NATIVE_DATE_FORMAT = 'YYYY-MM-DD';
const CUSTOM_DATE_FORMAT = 'dd.MM.yyyy';
const NATIVE_DATE_FORMAT = 'yyyy-MM-dd';
const IS_BROWSER = typeof window !== 'undefined';
const SUPPORTS_INPUT_TYPE_DATE = IS_BROWSER && isInputDateSupported();

Expand Down Expand Up @@ -569,7 +569,7 @@ export class CalendarInput extends React.Component<CalendarInputProps> {
// Копируем пришедший из аргументов SyntheticEvent для дальнейшего редактирования
const resultEvent = {
...event,
// Трансформируем нативную YYYY-MM-DD дату в кастомный формат на вывод в коллбэках
// Трансформируем нативную yyyy-MM-dd дату в кастомный формат на вывод в коллбэках
target: { value: changeDateFormat(event.target.value, NATIVE_DATE_FORMAT, CUSTOM_DATE_FORMAT) },
};

Expand All @@ -592,7 +592,7 @@ export class CalendarInput extends React.Component<CalendarInputProps> {
// Копируем пришедший из аргументов SyntheticEvent для дальнейшего редактирования
const resultEvent = {
...event,
// Трансформируем нативную YYYY-MM-DD дату в кастомный формат на вывод в коллбэках
// Трансформируем нативную yyyy-MM-dd дату в кастомный формат на вывод в коллбэках
target: { value: changeDateFormat(event.target.value, NATIVE_DATE_FORMAT, CUSTOM_DATE_FORMAT) },
};

Expand Down
7 changes: 4 additions & 3 deletions src/calendar-input/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import getTime from 'date-fns/get_time';
import startOfDay from 'date-fns/start_of_day';
import getTime from 'date-fns/getTime';
import startOfDay from 'date-fns/startOfDay';
import formatDate from 'date-fns/format';
import isDateValid from 'date-fns/is_valid';
import isDateValid from 'date-fns/isValid';

import { parse } from '../lib/date-utils';

/**
Expand Down
Loading