cockpit
cockpit copied to clipboard
"Invalid date format" when setting clock to "manual" using french language.
Explain what happens
-
Set french language
-
Go to the overview page and set system time without NTP (manual mode).
-
setting date/time with manual mode throw an error "Invalid date format".
Version of Cockpit
295
Where is the problem in Cockpit?
Overview
Server operating system
other
Server operating system version
No response
What browsers are you using?
Firefox, Chrome
System log
No response
Thanks for the report, I can reproduce the issue fine. Debugging this:
In pkg/lib/serverTime.js we pass
const new_date = new Date("21 juil. 2023");
Normally it is:
Fri Jul 21 2023 00:00:00 GMT+0200 (Central European Summer Time)
service.js:212 DBusError {problem: null, name: 'org.freedesktop.DBus.Error.UnknownInterface', message: "Unknown interface 'org.freedesktop.systemd1.Service'.", toString: ƒ}
The value comes from the <DatePicker> itself.
This isn't just French, German fails as well.
Ok, I was in the debugging, what we try is:
date 14/07/2023
serverTime.js:705 14/07/2023 Invalid Date
new Date("14/07/2023")
Invalid Date
That is valid as a US date, but not for a French locale.
Ok, writing this all up:
It turns out we have multiple issues here:
Dialog UX issue with displaying dates
Shown when opening:
Shown when changing
US date is always saved
So the whole invalid format issue is because we set manual_date to DD/MM/YYYY always which is wrong because Date is locale dependent in JavaScript so that throws an invalid date error.
However, the onChange method of the DatePicker does return a valid JS Date object, in it's third parameter
date
Wed Jul 12 2023 00:00:00 GMT+0200 (Central European Summer Time)
d
'12/07/2023'
So we should use that, however the code change_time code takes a datestr/timestr and passes it over to date. So the question is if my server's locale is French does date --date=14/07/2023 even work?
That seems to work?
[jelle@t14s][~]%LANG=de_DE date --date="12/07/2023"
Thu Dec 7 00:00:00 CET 2023
Refactor JS promises
change_time should not have to be wrapped into another Promise.
Hello @jelly, on my side I confirm it seams to work
I have the same problem in the German UI. If I type a date in the format "yyyy-mm-dd" the set-time-function works