diff --git a/migration/i9/oracle/202208282331_IDEMPIERE-5399.sql b/migration/i9/oracle/202208282331_IDEMPIERE-5399.sql new file mode 100644 index 0000000000..a7d5155cd6 --- /dev/null +++ b/migration/i9/oracle/202208282331_IDEMPIERE-5399.sql @@ -0,0 +1,25 @@ +SET SERVEROUTPUT ON + +BEGIN + FOR r IN ( +SELECT 'UPDATE '||t.tablename + ||' SET '||c.columnname||' = TO_DATE(''1970-01-01 '' || to_char('||c.columnname||', ''HH24:MI:SS''), ''yyyy-mm-dd HH24:MI:SS'') ' + ||'WHERE '||c.columnname||' IS NOT NULL AND ' + ||c.columnname||' != TO_DATE(''1970-01-01 '' || to_char('||c.columnname||', ''HH24:MI:SS''), ''yyyy-mm-dd HH24:MI:SS'')' + AS cmd + FROM ad_table t JOIN ad_column c USING (ad_table_id) + WHERE c.ad_reference_id = 24 + AND t.isview='N' + ORDER BY t.tablename, c.columnname +) + LOOP + EXECUTE IMMEDIATE r.cmd; + DBMS_OUTPUT.PUT_LINE(r.cmd); + DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT) || ' rows affected'); + END LOOP; +END; +/ + +SELECT register_migration_script('202208282331_IDEMPIERE-5399.sql') FROM dual +; + diff --git a/migration/i9/postgresql/202208282331_IDEMPIERE-5399.sql b/migration/i9/postgresql/202208282331_IDEMPIERE-5399.sql new file mode 100644 index 0000000000..e34b94a782 --- /dev/null +++ b/migration/i9/postgresql/202208282331_IDEMPIERE-5399.sql @@ -0,0 +1,28 @@ +DO $$ +<> +DECLARE + cmd varchar; + cnt integer; +BEGIN + FOR cmd IN + SELECT 'UPDATE '||t.tablename + ||' SET '||c.columnname||' = to_timestamp(''1970-01-01 '' || to_char('||c.columnname||', ''HH24:MI:SS''), ''yyyy-mm-dd HH24:MI:SS'')::timestamp ' + ||'WHERE '||c.columnname||' IS NOT NULL AND ' + ||c.columnname||' != to_timestamp(''1970-01-01 '' || to_char('||c.columnname||', ''HH24:MI:SS''), ''yyyy-mm-dd HH24:MI:SS'')::timestamp' + AS cmd + FROM ad_table t JOIN ad_column c USING (ad_table_id) + WHERE c.ad_reference_id = 24 + AND t.isview='N' + ORDER BY t.tablename, c.columnname + LOOP + EXECUTE cmd; + GET DIAGNOSTICS cnt = ROW_COUNT; + RAISE NOTICE '%', cmd; + RAISE NOTICE '% rows updated', cnt; + END LOOP; +END fix_times +$$; + +SELECT register_migration_script('202208282331_IDEMPIERE-5399.sql') FROM dual +; + diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java index 95435dfc98..1c800f6c0c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WTimeEditor.java @@ -14,6 +14,7 @@ package org.adempiere.webui.editor; import java.sql.Timestamp; +import java.util.Calendar; import java.util.Date; import java.util.logging.Level; @@ -122,11 +123,19 @@ public class WTimeEditor extends WEditor implements ContextMenuListener if (Events.ON_CHANGE.equalsIgnoreCase(event.getName()) || Events.ON_OK.equalsIgnoreCase(event.getName())) { Date date = getComponent().getValue(); + Timestamp newValue = null; if (date != null) { - newValue = new Timestamp(date.getTime()); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.YEAR, 1970); + cal.set(Calendar.MONTH, 0); + cal.set(Calendar.DAY_OF_MONTH, 1); + Date dateIn1970 = new Date(cal.getTimeInMillis()); + getComponent().setValue(dateIn1970); + newValue = new Timestamp(dateIn1970.getTime()); } if (oldValue != null && newValue != null && oldValue.equals(newValue)) {