Commit 5c4a03f6 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_web_renderjs_ui: datetime field formats date in the interface language

Also hide seconds as it weights down the interface, and to follow the behavior of XML style
parent 74f37187
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
]; ];
rJS(window) rJS(window)
.declareAcquiredMethod('getSelectedLanguage', 'getSelectedLanguage')
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var field_json = options.field_json || {}, var field_json = options.field_json || {},
state_dict = { state_dict = {
...@@ -228,24 +228,52 @@ ...@@ -228,24 +228,52 @@
} else { } else {
queue queue
.push(function (gadget_list) { .push(function (gadget_list) {
var text_content = "", return RSVP.all([
gadget.getSelectedLanguage(),
gadget_list
]);
})
.push(function (result_list) {
var language = result_list[0],
gadget_list = result_list[1],
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(); 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;
} }
} else { } else {
//get timezone difference between server and local browser //get timezone difference between server and local browser
offset_time_zone = timezone + (state_date.getTimezoneOffset() / 60); offset_time_zone = timezone + (state_date.getTimezoneOffset() / 60);
//adjust hour in order to get correct date time string //adjust hour in order to get correct date time string
state_date.setUTCHours(state_date.getUTCHours() + offset_time_zone); state_date.setUTCHours(state_date.getUTCHours() + offset_time_zone);
text_content = state_date.toLocaleDateString(); 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;
} }
} }
} }
......
...@@ -142,11 +142,13 @@ ...@@ -142,11 +142,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -190,16 +192,20 @@ ...@@ -190,16 +192,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -222,7 +228,7 @@ ...@@ -222,7 +228,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>965.12118.35525.1655</string> </value> <value> <string>980.55051.50282.19404</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -240,7 +246,7 @@ ...@@ -240,7 +246,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1517930509.55</float> <float>1577775957.85</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -249,7 +255,9 @@ ...@@ -249,7 +255,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -153,6 +153,19 @@ ...@@ -153,6 +153,19 @@
<td>glob:${now}*</td> <td>glob:${now}*</td>
</tr> </tr>
<!-- Seconds should also be invisible in non-editable mode,
and that output follows locale (here "en") -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/toggle_editable_mode" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/verify_is_non_editable_mode" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_content_loaded" />
<tr>
<td>assertText</td>
<td>//div[@data-gadget-scope='field_my_start_date']//p</td>
<td>regexp:1?\d/[123]?\d/20\d\d \d\d?:\d\d (AM|PM)</td>
</tr>
</tbody></table> </tbody></table>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//div[@data-gadget-scope='field_my_start_date']//div[@data-gadget-scope='field']//p[contains(text(), '11:00:00')]</td> <td>//div[@data-gadget-scope='field_my_start_date']//div[@data-gadget-scope='field']//p[contains(text(), '11:00')]</td>
<td></td> <td></td>
</tr> </tr>
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//div[@data-gadget-scope='field_my_start_date']//div[@data-gadget-scope='field']//p[contains(text(), '11:00:00')]</td> <td>//div[@data-gadget-scope='field_my_start_date']//div[@data-gadget-scope='field']//p[contains(text(), '11:00')]</td>
<td></td> <td></td>
</tr> </tr>
......
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