]> git.proxmox.com Git - proxmox-widget-toolkit.git/commit
datetimefield: fix changing date to end of month from short months
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 27 Feb 2024 13:23:24 +0000 (14:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 27 Feb 2024 13:33:41 +0000 (14:33 +0100)
commit43b978658e60882b9253795169d3ce94ff43b288
tree21d965c233c076097a00b97d8e2f0cd5e6b8c5a5
parentbbb7ecbe360531b6154787e69ccbc01e1176afbc
datetimefield: fix changing date to end of month from short months

When selecting a new date, we get a date object from the currently
selected date before the change. If that month has less days than what
was selected for the new month, `setDate` will wrap that to the
following month since the old month is still selected there.

For example:

select any date in april (has 30 days)
then select the 31th of january

this will actually select the 1st of january since we first get

setDate: 20xx-04-XX -> 20xx-04-31 (wrap) -> 20xx-05-01
setMonth: 20xx-05-01 -> 20xx-01-01

To fix this, use the additional parameters of setFullYear[0] to set
all of them simultaneously

0: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/setFullYear

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/form/DateTimeField.js