Skip to content

Commit

Permalink
Merge 5303da8 into cf58c76
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLynn committed Feb 21, 2024
2 parents cf58c76 + 5303da8 commit b0246e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
9 changes: 9 additions & 0 deletions cypress/e2e/timePicker.spec.js
Expand Up @@ -61,4 +61,13 @@ describe('timePicker', () => {
cy.get('body').click('right');
cy.get('.semi-input-default').eq(1).should('have.value', '10:24:18');
});

it('timezone + disabledHours', () => {
cy.visit('http://127.0.0.1:6006/iframe.html?id=timepicker--fix-2082&args=&viewMode=story');
cy.get('.semi-input-default').eq(0).click();
cy.get('.semi-timepicker-panel-list-hour').eq(0).contains('07').click({ force: true });
cy.get('.semi-timepicker-panel-list-minute').eq(0).contains('10').click({ force: true });
cy.get('body').click('right');
cy.get('.semi-input-default').eq(0).should('have.value', '07:10');
});
});
5 changes: 4 additions & 1 deletion packages/semi-foundation/timePicker/foundation.ts
Expand Up @@ -202,8 +202,8 @@ class TimePickerFoundation<P = Record<string, any>, S = Record<string, any>> ext
const { value, timeZone, __prevTimeZone } = props;

let dates = this.parseValue(value);
const invalid = this.validateDates(dates);

let invalid = dates.some(d => isNaN(Number(d)));
if (!invalid) {
if (this.isValidTimeZone(timeZone)) {
dates = dates.map(date =>
Expand All @@ -213,6 +213,9 @@ class TimePickerFoundation<P = Record<string, any>, S = Record<string, any>> ext
)
);
}
invalid = dates.some(d =>
this.isDisabledHMS({ hours: d.getHours(), minutes: d.getMinutes(), seconds: d.getSeconds() })
);
}
const inputValue = this.formatValue(dates);

Expand Down
21 changes: 20 additions & 1 deletion packages/semi-ui/timePicker/_story/timepicker.stories.jsx
@@ -1,6 +1,6 @@
import React, { Component, useState } from 'react';
import TimePickerPanel from '../index';
import { TimePicker as BasicTimePicker, Button, Form, Popover } from '../../index';
import { TimePicker as BasicTimePicker, Button, Form, Popover, ConfigProvider } from '../../index';
import { strings } from '@douyinfe/semi-foundation/timePicker/constants';
import { get } from 'lodash';

Expand Down Expand Up @@ -356,3 +356,22 @@ export const Fix1953 = () => {
<TimePicker format={'HH'} defaultValue={'10'}/>
);
};

export const Fix2082 = () => {
const [date, setDate] = useState(new Date());
return (
<ConfigProvider timeZone={10}>
<div style={{ width: 300 }}>
<h5 style={{ margin: 10 }}>TimePicker:</h5>
<TimePicker
disabledHours={v => [5]}
format="HH:mm"
value={date}
onChange={(date, dateString) => {
console.log('日期', date);
setDate(date)} }
/>
</div>
</ConfigProvider>
);
};

0 comments on commit b0246e8

Please sign in to comment.