Commit 1f55f616 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_web_renderjs_ui: unify the behavior of timezone calculation between both interfaces

Causing the browser time to be used instead of the calculated time of the server, which was incoherent with previous behavior (fix 5c4a03f6)

Display the timezone (if the field is configured like that) in both editable and non-editable mode

See merge request !1113
parents d16b9ff9 f634ac3e
...@@ -31,6 +31,28 @@ ...@@ -31,6 +31,28 @@
["GMT+12", "+1200"] ["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) rJS(window)
.declareAcquiredMethod('getSelectedLanguage', 'getSelectedLanguage') .declareAcquiredMethod('getSelectedLanguage', 'getSelectedLanguage')
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
...@@ -232,35 +254,9 @@ ...@@ -232,35 +254,9 @@
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) {
text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date;
}
} else {
//get timezone difference between server and local browser //get timezone difference between server and local browser
offset_time_zone = timezone + offset_time_zone = timezone +
(state_date.getTimezoneOffset() / 60); (state_date.getTimezoneOffset() / 60);
...@@ -269,7 +265,12 @@ ...@@ -269,7 +265,12 @@
offset_time_zone); 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 += " " + locale_formatted_state_date; text_content += " " +
formatDateToLocaleFormatString(state_date, language);
}
if (gadget.state.timezone_style) {
if (!gadget.state.date_only) {
text_content += " " + ZONE_LIST[timezone + 12][0];
} }
} }
} }
......
...@@ -228,7 +228,7 @@ ...@@ -228,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.20840.63890.24627</string> </value> <value> <string>983.56055.11203.16827</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -246,8 +246,8 @@ ...@@ -246,8 +246,8 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1583399782.26</float> <float>1589358221.58</float>
<string>UTC</string> <string>GMT+0</string>
</tuple> </tuple>
</state> </state>
</object> </object>
......
...@@ -82,6 +82,18 @@ ...@@ -82,6 +82,18 @@
<td></td> <td></td>
</tr> </tr>
<tr>
<td>assertText</td>
<td>//div[@data-gadget-scope='field_my_stop_date']//div[@data-gadget-scope='field']//p</td>
<td>glob:*12:00*GMT+5</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> <tr>
<td>storeLocation</td> <td>storeLocation</td>
<td>url</td> <td>url</td>
...@@ -126,6 +138,12 @@ ...@@ -126,6 +138,12 @@
</tr> </tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" /> <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> <tr>
<td>assertElementPresent</td> <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>//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