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
Pipeline #9445 failed with stage
...@@ -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,44 +254,23 @@ ...@@ -232,44 +254,23 @@
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 //get timezone difference between server and local browser
* to hide seconds. Unfortunately it doesn't work in older offset_time_zone = timezone +
* versions of firefox. Luckily, by using (state_date.getTimezoneOffset() / 60);
* {hour: "numeric", minute: "numeric"} //adjust hour in order to get correct date time string
* it hides seconds, and still respects the locale. state_date.setUTCHours(state_date.getUTCHours() +
* >> date = new Date(2019, 1, 1, 1, 1) offset_time_zone);
* >> date.toLocaleTimeString( text_content = state_date.toLocaleDateString(language);
* 'en', {hour: "numeric", minute: "numeric"} if (!gadget.state.date_only) {
* ) text_content += " " +
* "1:01 AM" formatDateToLocaleFormatString(state_date, language);
* >> 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);
if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date;
}
} else {
//get timezone difference between server and local browser
offset_time_zone = timezone +
(state_date.getTimezoneOffset() / 60);
//adjust hour in order to get correct date time string
state_date.setUTCHours(state_date.getUTCHours() +
offset_time_zone);
text_content = state_date.toLocaleDateString(language);
if (!gadget.state.date_only) { if (!gadget.state.date_only) {
text_content += " " + locale_formatted_state_date; text_content += " " + ZONE_LIST[timezone + 12][0];
} }
} }
} }
...@@ -402,4 +403,4 @@ ...@@ -402,4 +403,4 @@
return true; return true;
}, {mutex: 'changestate'}); }, {mutex: 'changestate'});
}(window, rJS, RSVP)); }(window, rJS, RSVP));
\ No newline at end of file
...@@ -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