Skip to content

Commit

Permalink
Merge 786e7e5 into d0f8509
Browse files Browse the repository at this point in the history
  • Loading branch information
jessieyan committed Dec 5, 2022
2 parents d0f8509 + 786e7e5 commit 2999d44
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ const DateTimePicker = ({
id={`${id}-start-time`}
invalid={absoluteStartTimeInvalid}
labelText={mergedI18n.startTimeLabel}
value={absoluteValue ? absoluteValue.startTime : '00:00'}
value={absoluteValue ? absoluteValue.startTime : null}
i18n={i18n}
onChange={onAbsoluteStartTimeChange}
spinner
Expand All @@ -959,7 +959,7 @@ const DateTimePicker = ({
id={`${id}-end-time`}
invalid={absoluteEndTimeInvalid}
labelText={mergedI18n.endTimeLabel}
value={absoluteValue ? absoluteValue.endTime : '00:00'}
value={absoluteValue ? absoluteValue.endTime : null}
i18n={i18n}
onChange={onAbsoluteEndTimeChange}
spinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ describe('DateTimePicker', () => {
timeRangeValue: {
end: Cypress.sinon.match.any,
endDate: now.format(`MM/[12]/YYYY`),
endTime: '00:00',
endTime: null,
start: Cypress.sinon.match.any,
startDate: lastMonth.format(`MM/[20]/YYYY`),
startTime: '00:00',
startTime: null,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,14 @@ describe('DateTimePicker', () => {
1
);
});
it('should fallback to 00:00 for absolute times when none given', () => {
it('should fallback to empty for absolute times when none given', () => {
render(<DateTimePicker {...dateTimePickerProps} id="picker-test" />);
jest.runAllTimers();

userEvent.click(screen.getByTestId('date-time-picker__field'));
userEvent.click(screen.getByText('Custom Range'));
userEvent.click(screen.getByText('Absolute'));
expect(screen.getAllByTestId('time-picker-spinner')[0]).toHaveValue('00:00');
expect(screen.getAllByTestId('time-picker-spinner')[0]).toHaveValue('');
});
it('should not show the Custom Range link when showCustomRangeLink:false', () => {
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,16 +794,12 @@ describe('DateTimePickerV2', () => {
timeRangeValue: {
end: Cypress.sinon.match.any,
endDate: now.format(`MM/[12]/YYYY`),
endTime: '00:00',
endTime: null,
start: Cypress.sinon.match.any,
startDate: lastMonth.format(`MM/[20]/YYYY`),
startTime: '00:00',
humanValue: `${lastMonth.format('YYYY-MM-[20]')} 00:00 to ${now.format(
'YYYY-MM-[12]'
)} 00:00`,
tooltipValue: `${lastMonth.format('YYYY-MM-[20]')} 00:00 to ${now.format(
'YYYY-MM-[12]'
)} 00:00`,
startTime: null,
humanValue: `${lastMonth.format('YYYY-MM-[20]')} to ${now.format('YYYY-MM-[12]')}`,
tooltipValue: `${lastMonth.format('YYYY-MM-[20]')} to ${now.format('YYYY-MM-[12]')}`,
},
});
});
Expand Down Expand Up @@ -845,16 +841,12 @@ describe('DateTimePickerV2', () => {
timeRangeValue: {
end: Cypress.sinon.match.any,
endDate: now.format(`MM/[12]/YYYY`),
endTime: '00:00',
endTime: null,
start: Cypress.sinon.match.any,
startDate: lastMonth.format(`MM/[20]/YYYY`),
startTime: '00:00',
humanValue: `${lastMonth.format('YYYY-MM-[20]')} 00:00 to ${now.format(
'YYYY-MM-[12]'
)} 00:00`,
tooltipValue: `${lastMonth.format('YYYY-MM-[20]')} 00:00 to ${now.format(
'YYYY-MM-[12]'
)} 00:00`,
startTime: null,
humanValue: `${lastMonth.format('YYYY-MM-[20]')} to ${now.format('YYYY-MM-[12]')}`,
tooltipValue: `${lastMonth.format('YYYY-MM-[20]')} to ${now.format('YYYY-MM-[12]')}`,
},
timeSingleValue: null,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ describe('DateTimePickerV2', () => {
/>
);

userEvent.click(screen.getByText('2021-08-01 00:00 to 2021-08-06 00:00'));
userEvent.click(screen.getByText('2021-08-01 to 2021-08-06'));
expect(screen.queryByLabelText('Start time')).toBeNull();
expect(screen.queryByLabelText('End time')).toBeNull();
});
Expand Down Expand Up @@ -1361,17 +1361,17 @@ describe('DateTimePickerV2', () => {
);
});

it('should fallback to 00:00 for absolute times when none given', () => {
it('should fallback to empty for absolute times when none given', () => {
render(<DateTimePicker {...dateTimePickerProps} id="picker-test" />);
jest.runAllTimers();

userEvent.click(screen.getByTestId('date-time-picker__field'));
userEvent.click(screen.getByText('Custom Range'));
userEvent.click(screen.getByText('Absolute'));
expect(screen.getAllByTestId('time-picker-spinner')[0]).toHaveValue('00:00');
expect(screen.getAllByTestId('time-picker-spinner')[0]).toHaveValue('');
});

it('should fallback to 00:00 for absolute times when none given (new time spinner)', () => {
it('should fallback to empty for absolute times when none given (new time spinner)', () => {
render(<DateTimePicker useNewTimeSpinner {...dateTimePickerProps} id="picker-test" />);
jest.runAllTimers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ const DateTimePicker = ({
} else if (customRangeKind === PICKER_KINDS.ABSOLUTE) {
value.absolute = {
...absoluteValue,
startTime: hasTimeInput ? rangeStartTimeValue : '00:00',
endTime: hasTimeInput ? rangeEndTimeValue : '00:00',
startTime: hasTimeInput ? rangeStartTimeValue : null,
endTime: hasTimeInput ? rangeEndTimeValue : null,
};
} else {
value.single = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ const DateTimePicker = ({
id={`${id}-start-time`}
invalid={absoluteStartTimeInvalid}
labelText={mergedI18n.startTimeLabel}
value={absoluteValue ? absoluteValue.startTime : '00:00'}
value={absoluteValue ? absoluteValue.startTime : null}
i18n={i18n}
onChange={onAbsoluteStartTimeChange}
spinner
Expand All @@ -1029,7 +1029,7 @@ const DateTimePicker = ({
id={`${id}-end-time`}
invalid={absoluteEndTimeInvalid}
labelText={mergedI18n.endTimeLabel}
value={absoluteValue ? absoluteValue.endTime : '00:00'}
value={absoluteValue ? absoluteValue.endTime : null}
i18n={i18n}
onChange={onAbsoluteEndTimeChange}
spinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const parseValue = (timeRange, dateTimeMask, toLabel) => {

returnValue.absolute.start = new Date(startDate.valueOf());

const startTimeValue = value.startTime
? `${dayjs(startDate).format(dateTimeMask)}`
: `${dayjs(startDate).format(dateTimeMask)}`.split(' ')[0];

if (value.end ?? value.endDate) {
let endDate = dayjs(value.end ?? value.endDate);
if (value.endTime) {
Expand All @@ -122,14 +126,15 @@ export const parseValue = (timeRange, dateTimeMask, toLabel) => {
endDate = endDate.hours(formatedEndTime.split(':')[0]);
endDate = endDate.minutes(formatedEndTime.split(':')[1]);
}

const endTimeValue = value.endTime
? `${dayjs(endDate).format(dateTimeMask)}`
: `${dayjs(endDate).format(dateTimeMask)}`.split(' ')[0];

returnValue.absolute.end = new Date(endDate.valueOf());
readableValue = `${dayjs(startDate).format(dateTimeMask)} ${toLabel} ${dayjs(
endDate
).format(dateTimeMask)}`;
readableValue = `${startTimeValue} ${toLabel} ${endTimeValue}`;
} else {
readableValue = `${dayjs(startDate).format(dateTimeMask)} ${toLabel} ${dayjs(
startDate
).format(dateTimeMask)}`;
readableValue = `${startTimeValue} ${toLabel} ${startTimeValue}`;
}
break;
}
Expand All @@ -149,7 +154,9 @@ export const parseValue = (timeRange, dateTimeMask, toLabel) => {
startDate = startDate.minutes(formatedStartTime.split(':')[1]);
}
returnValue.single.start = new Date(startDate.valueOf());
readableValue = `${dayjs(startDate).format(dateTimeMask)}`;
readableValue = value.startTime
? `${dayjs(startDate).format(dateTimeMask)}`
: `${dayjs(startDate).format(dateTimeMask)}`.split(' ')[0];
break;
}
default:
Expand Down Expand Up @@ -366,9 +373,9 @@ export const useAbsoluteDateTimeValue = () => {
const resetAbsoluteValue = () => {
setAbsoluteValue({
startDate: '',
startTime: '00:00',
startTime: null,
endDate: '',
endTime: '00:00',
endTime: null,
});
};

Expand Down

0 comments on commit 2999d44

Please sign in to comment.