cockpit icon indicating copy to clipboard operation
cockpit copied to clipboard

"Invalid date format" when setting clock to "manual" using french language.

Open jciesla opened this issue 2 years ago • 5 comments

Explain what happens

  1. Set french language image

  2. Go to the overview page and set system time without NTP (manual mode). image

  3. 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

jciesla avatar Jul 10 '23 16:07 jciesla

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.

jelly avatar Jul 21 '23 07:07 jelly

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.

jelly avatar Jul 21 '23 11:07 jelly

Ok, writing this all up:

It turns out we have multiple issues here:

Dialog UX issue with displaying dates

Shown when opening:

image

Shown when changing

image

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.

jelly avatar Jul 21 '23 11:07 jelly

Hello @jelly, on my side I confirm it seams to work

image

jciesla avatar Aug 25 '23 12:08 jciesla

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

image

Bernd-Wissler-KBR avatar May 06 '24 12:05 Bernd-Wissler-KBR