fix(input-date): use timezone offset in serializedValue (#608)
This commit is contained in:
parent
7c45dd6839
commit
8f2927be4c
2 changed files with 7 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { LocalizeMixin, formatDate, parseDate } from '@lion/localize';
|
||||
import { LionInput } from '@lion/input';
|
||||
import { formatDate, LocalizeMixin, parseDate } from '@lion/localize';
|
||||
import { IsDate } from '@lion/validate';
|
||||
|
||||
/**
|
||||
|
|
@ -41,7 +41,10 @@ export class LionInputDate extends LocalizeMixin(LionInput) {
|
|||
if (!(modelValue instanceof Date)) {
|
||||
return '';
|
||||
}
|
||||
return modelValue.toISOString().slice(0, 10);
|
||||
// modelValue is localized, so we take the timezone offset in milliseconds and subtract it
|
||||
// before converting it to ISO string
|
||||
const offset = modelValue.getTimezoneOffset() * 60000;
|
||||
return new Date(modelValue - offset).toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
|
|
|
|||
|
|
@ -141,9 +141,9 @@ describe('<lion-input-date>', () => {
|
|||
it('serializes to iso format', async () => {
|
||||
const el = await fixture(
|
||||
html`
|
||||
<lion-input-date .modelValue="${new Date('2000-12-12')}"></lion-input-date>
|
||||
<lion-input-date .modelValue="${new Date('2000/12/15')}"></lion-input-date>
|
||||
`,
|
||||
);
|
||||
expect(el.serializedValue).to.equal('2000-12-12');
|
||||
expect(el.serializedValue).to.equal('2000-12-15');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue