fix(datetime): confirm method now uses selected date (#24827)

Resolves #24823
This commit is contained in:
Sean Perkins
2022-02-23 15:14:53 -05:00
committed by GitHub
parent 33292fbd92
commit c35b898f1d
2 changed files with 41 additions and 3 deletions

View File

@ -424,10 +424,10 @@ export class Datetime implements ComponentInterface {
* the date that is currently selected, otherwise
* there can be 1 hr difference when dealing w/ DST
*/
const date = new Date(convertDataToISO(this.workingParts));
this.workingParts.tzOffset = date.getTimezoneOffset() * -1;
const date = new Date(convertDataToISO(this.activeParts));
this.activeParts.tzOffset = date.getTimezoneOffset() * -1;
this.value = convertDataToISO(this.workingParts);
this.value = convertDataToISO(this.activeParts);
if (closeOverlay) {
this.closeParentOverlay();

View File

@ -110,3 +110,41 @@ test('datetime:rtl: basic', async () => {
const compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();
});
describe('datetime: confirm date', () => {
test('should set the date value based on the selected date', async () => {
const page = await newE2EPage({
html: `
<button>Bind datetimeMonthDidChange event</button>
<ion-datetime value="2021-12-25T12:40:00.000Z"></ion-datetime>
<script type="module">
import { InitMonthDidChangeEvent } from '/src/components/datetime/test/utils/month-did-change-event.js';
document.querySelector('button').addEventListener('click', function() {
InitMonthDidChangeEvent();
});
</script>
`
});
const eventButton = await page.find('button');
await eventButton.click();
const buttons = await page.findAll('ion-datetime >>> .calendar-next-prev ion-button');
await buttons[1].click();
await page.waitForEvent('datetimeMonthDidChange');
await page.$eval('ion-datetime', async (el: any) => {
await el.confirm();
});
const value = await (await page.find('ion-datetime')).getProperty('value');
expect(value).toMatch('2021-12-25T12:40:00');
});
});