Skip to content

Commit

Permalink
fix(datetime): confirm method now uses selected date (#24827)
Browse files Browse the repository at this point in the history
Resolves #24823
  • Loading branch information
sean-perkins authored Feb 23, 2022
1 parent 33292fb commit c35b898
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/src/components/datetime/datetime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 38 additions & 0 deletions core/src/components/datetime/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});

0 comments on commit c35b898

Please sign in to comment.