Commit 7bd0bac2 authored by Nicolas Wavrant's avatar Nicolas Wavrant

fixup! erp5_web_renderjs_ui: datetime field formats date in the interface language

parent d1f19c42
...@@ -238,16 +238,33 @@ ...@@ -238,16 +238,33 @@
gadget_list = result_list[1], gadget_list = result_list[1],
text_content = "", text_content = "",
state_date, state_date,
locale_formatted_state_date,
offset_time_zone; offset_time_zone;
if (gadget.state.value) { if (gadget.state.value) {
state_date = new Date(gadget.state.value); state_date = new Date(gadget.state.value);
/* Ideally we would like to use {timeStyle: "short"} as option
* to hide seconds. Unfortunately it doesn't work in older
* versions of firefox. Luckily, by using
* {hour: "numeric", minute: "numeric"}
* it hides seconds, and still respects the locale.
* >> date = new Date(2019, 1, 1, 1, 1)
* >> date.toLocaleTimeString(
* 'en', {hour: "numeric", minute: "numeric"}
* )
* "1:01 AM"
* >> date.toLocaleTimeString(
* 'fr', {hour: "numeric", minute: "numeric"}
* )
* "01:01"
*/
locale_formatted_state_date = state_date.toLocaleTimeString(
language,
{hour: "numeric", minute: "numeric"}
);
if (gadget.state.timezone_style) { if (gadget.state.timezone_style) {
text_content = state_date.toLocaleDateString(language); text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) { if (!gadget.state.date_only) {
text_content += " " + state_date.toLocaleTimeString( text_content += " " + locale_formatted_state_date;
language,
{timeStyle: "short"}
);
} }
} else { } else {
//get timezone difference between server and local browser //get timezone difference between server and local browser
...@@ -256,10 +273,7 @@ ...@@ -256,10 +273,7 @@
state_date.setUTCHours(state_date.getUTCHours() + offset_time_zone); state_date.setUTCHours(state_date.getUTCHours() + offset_time_zone);
text_content = state_date.toLocaleDateString(language); text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) { if (!gadget.state.date_only) {
text_content += " " + state_date.toLocaleTimeString( text_content += " " + locale_formatted_state_date;
language,
{timeStyle: "short"}
);
} }
} }
} }
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>980.48184.20620.63641</string> </value> <value> <string>980.55051.50282.19404</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1577760705.94</float> <float>1577775957.85</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment