IDEMPIERE-5399 Data type Time is mostly useless (#1456)

This commit is contained in:
Carlos Ruiz 2022-08-30 14:14:17 +02:00 committed by GitHub
parent 79d9efb8f5
commit 8cd20b9e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 1 deletions

View File

@ -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
;

View File

@ -0,0 +1,28 @@
DO $$
<<fix_times>>
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
;

View File

@ -14,6 +14,7 @@
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.logging.Level; 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())) if (Events.ON_CHANGE.equalsIgnoreCase(event.getName()) || Events.ON_OK.equalsIgnoreCase(event.getName()))
{ {
Date date = getComponent().getValue(); Date date = getComponent().getValue();
Timestamp newValue = null; Timestamp newValue = null;
if (date != 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)) { if (oldValue != null && newValue != null && oldValue.equals(newValue)) {