From 8de5eb317a61d9e7f8af8652267acb4f9f263a9c Mon Sep 17 00:00:00 2001
From: Yusei Tahara <yusei@nexedi.com>
Date: Tue, 18 Feb 2020 04:24:29 +0100
Subject: [PATCH] erp5_web_renderjs_ui: Change date separator from a dash to a
 slash before sending query to Zope. If date separator was a dash, Zope
 DateTime does not use local timezone and date search does not work.

---
 .../rjs_gadget_erp5_searcheditor_js.js        | 22 ++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_searcheditor_js.js b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_searcheditor_js.js
index 8ce499bf59..50ec6d122d 100644
--- a/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_searcheditor_js.js
+++ b/bt5/erp5_web_renderjs_ui/PathTemplateItem/web_page_module/rjs_gadget_erp5_searcheditor_js.js
@@ -265,6 +265,15 @@
     if (operator_default_list === NUMERIC) {
       if (query_dict.key.indexOf("date") !== -1) {
         input_type = "date";
+        if (query_dict.value) {
+          // Zope DateTime uses local timezone automatically if date seperator
+          // was a slash like 2020/02/08, but if it was a dash like 2020-02-08,
+          // Zope DateTime ignores local timezone and timezone become GMT+0.
+          // Then if server is not located in GMT+0 zone, date search does not
+          // work. Since HTML5 date input field uses dash as a separator, it
+          // must be changed to slash before sending query to Zope.
+          query_dict.value = query_dict.value.replace(/\//g, "-");
+        }
       } else {
         input_type = "number";
       }
@@ -392,7 +401,8 @@
       select_list,
       key,
       operator,
-      value;
+      value,
+      input_field;
 
     for (i = 0; i < filter_item_list.length; i += 1) {
       select_list = filter_item_list[i].querySelectorAll("select");
@@ -413,6 +423,16 @@
           /*jslint continue: false */
         }
         value = filter_item_list[i].querySelector("input").value;
+        input_field = filter_item_list[i].querySelector("input");
+        if (input_field.type === 'date' && value) {
+          // Zope DateTime uses local timezone automatically if date seperator
+          // was a slash like 2020/02/08, but if it was a dash like 2020-02-08,
+          // Zope DateTime ignores local timezone and timezone become GMT+0.
+          // Then if server is not located in GMT+0 zone, date search does not
+          // work. Since HTML5 date input field uses dash as a separator, it
+          // must be changed to slash before sending query to Zope.
+          value = value.replace(/-/g, "/");
+        }
       }
       state.query_list.push({
         type: "simple",
-- 
2.30.9