Commit 30ffec4e authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_web_renderjs_ui: fix re-use after change variable bug

causing the browser time to be used instead of the calculated time of the server, which was incoherent with previous behavior (fix 5c4a03f6)
parent 9f6e79ee
......@@ -31,6 +31,28 @@
["GMT+12", "+1200"]
];
function formatDateToLocaleFormatString(date, language) {
/* 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"
*/
return date.toLocaleTimeString(
language,
{hour: "numeric", minute: "numeric"}
);
}
rJS(window)
.declareAcquiredMethod('getSelectedLanguage', 'getSelectedLanguage')
.declareMethod('render', function (options) {
......@@ -232,33 +254,14 @@
gadget_list = result_list[1],
text_content = "",
state_date,
locale_formatted_state_date,
offset_time_zone;
if (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) {
text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date;
text_content += " " +
formatDateToLocaleFormatString(state_date, language);
}
} else {
//get timezone difference between server and local browser
......@@ -269,7 +272,8 @@
offset_time_zone);
text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date;
text_content += " " +
formatDateToLocaleFormatString(state_date, language);
}
}
}
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>982.20840.63890.24627</string> </value>
<value> <string>983.16851.20471.25753</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -246,7 +246,7 @@
</tuple>
<state>
<tuple>
<float>1583399782.26</float>
<float>1587092369.15</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -82,6 +82,19 @@
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<!-- Known bug, in non-editable mode the dates are translated to the client timezone as the timezone selector is not shown -->
<td>//div[@data-gadget-scope='field_my_stop_date']//div[@data-gadget-scope='field']//p[contains(text(), '7:00')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-scope='field_my_stop_date']//div[@data-gadget-scope='field']//p[@data-date='2016-12-21T12:00:00']</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>url</td>
......@@ -126,6 +139,12 @@
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-scope='field_my_stop_date']//div[@data-gadget-scope='field']//p[contains(text(), '12:00')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-scope='field_my_stop_date']//div[@data-gadget-scope='field']//p[@data-date='2016-12-21T12:00:00']</td>
......
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