Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/FormDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,11 @@ export default {
return date;
},
parsingInputDate(val) {
const date = moment(val, this.format).local(true);
// Check if user is typing, if the date is not valid, let the user continue
const date = this.dataFormat === "date" ? moment.utc(val, this.format, true) : moment.tz(val, this.format, true, getTimezone());
if (!date.isValid()) return "";
if (this.dataFormat === "date") {
return new Date(date.year(), date.month(), date.date());
}
return date.toDate();
},
/*
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/FormDatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,58 @@ describe('FormDatePicker', () => {
expect(wrapper.html()).not.toContain(validationError);
});

it('keeps the selected calendar day on Melbourne DST start', () => {
const previousTz = process.env.TZ;
process.env.TZ = 'Australia/Melbourne';

try {
window.ProcessMaker.user = {
timezone: 'Australia/Melbourne',
datetime_format: 'MM/DD/YYYY',
};

const wrapper = mount(FormDatePicker, {
propsData: {
dataFormat: 'date',
},
});

const parsed = wrapper.vm.parsingInputDate('10/04/2026');

expect(parsed.getFullYear()).toBe(2026);
expect(parsed.getMonth()).toBe(9);
expect(parsed.getDate()).toBe(4);
} finally {
process.env.TZ = previousTz;
}
});

it('keeps the selected calendar day on New Zealand DST start', () => {
const previousTz = process.env.TZ;
process.env.TZ = 'Pacific/Auckland';

try {
window.ProcessMaker.user = {
timezone: 'Pacific/Auckland',
datetime_format: 'MM/DD/YYYY',
};

const wrapper = mount(FormDatePicker, {
propsData: {
dataFormat: 'date',
},
});

const parsed = wrapper.vm.parsingInputDate('09/27/2026');

expect(parsed.getFullYear()).toBe(2026);
expect(parsed.getMonth()).toBe(8);
expect(parsed.getDate()).toBe(27);
} finally {
process.env.TZ = previousTz;
}
});

it('convert invalid value to current date', async () => {
const wrapper = mount(FormDatePicker, {
propsData: {
Expand Down
Loading