From 962fe09801582832860cfa2cd98d537ce5ee84cf Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 25 Mar 2011 22:10:35 -0500 Subject: [PATCH] BF [3075946] - Date problem on non-Christian Yr Locale, i.e.,Buddhist Yr https://sourceforge.net/tracker/?func=detail&atid=879332&aid=3075946&group_id=176962 --- .../src/org/compiere/model/GridField.java | 19 +++++++-- .../src/org/compiere/util/Env.java | 39 ++++++++++++++++--- .../src/org/compiere/grid/ed/Calendar.java | 18 ++++++--- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridField.java b/org.adempiere.base/src/org/compiere/model/GridField.java index d8ea903281..67a208efff 100644 --- a/org.adempiere.base/src/org/compiere/model/GridField.java +++ b/org.adempiere.base/src/org/compiere/model/GridField.java @@ -25,7 +25,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; import java.util.List; import java.util.Properties; import java.util.StringTokenizer; @@ -74,7 +77,7 @@ public class GridField /** * */ - private static final long serialVersionUID = 1124123543602986028L; + private static final long serialVersionUID = -6007475135643071025L; /** * Field Constructor. @@ -1358,8 +1361,18 @@ public class GridField { Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.ColumnName, (Timestamp)m_value); } - Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, - m_value==null ? null : m_value.toString().substring(0, m_value.toString().indexOf("."))); + // BUG:3075946 KTU - Fix Thai Date + //Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, + // m_value==null ? null : m_value.toString().substring(0, m_value.toString().indexOf("."))); + String stringValue = null; + if (m_value != null && !m_value.toString().equals("")) { + Calendar c1 = Calendar.getInstance(); + c1.setTime((Date) m_value); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + stringValue = sdf.format(c1.getTime()); + } + Env.setContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, m_vo.ColumnName, stringValue); + // KTU - Fix Thai Date } else { diff --git a/org.adempiere.base/src/org/compiere/util/Env.java b/org.adempiere.base/src/org/compiere/util/Env.java index 2dbe616ab3..e9bd7007bc 100644 --- a/org.adempiere.base/src/org/compiere/util/Env.java +++ b/org.adempiere.base/src/org/compiere/util/Env.java @@ -29,8 +29,10 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.MessageFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.Iterator; @@ -261,9 +263,15 @@ public final class Env } else { // JDBC Format 2005-05-09 00:00:00.0 - String stringValue = value.toString(); + // BUG:3075946 KTU, Fix Thai Date + //String stringValue = value.toString(); + String stringValue = ""; + Calendar c1 = Calendar.getInstance(); + c1.setTime(value); + stringValue = DisplayType.getTimestampFormat_Default().format(c1.getTime()); // Chop off .0 (nanos) - stringValue = stringValue.substring(0, stringValue.indexOf(".")); + //stringValue = stringValue.substring(0, stringValue.indexOf(".")); + // KTU ctx.setProperty(context, stringValue); getLogger().finer("Context " + context + "==" + stringValue); } @@ -333,9 +341,15 @@ public final class Env } else { // JDBC Format 2005-05-09 00:00:00.0 - String stringValue = value.toString(); + // BUG:3075946 KTU, Fix Thai year + //String stringValue = value.toString(); + String stringValue = ""; + Calendar c1 = Calendar.getInstance(); + c1.setTime(value); + stringValue = DisplayType.getTimestampFormat_Default().format(c1.getTime()); // Chop off .0 (nanos) - stringValue = stringValue.substring(0, stringValue.indexOf(".")); + //stringValue = stringValue.substring(0, stringValue.indexOf(".")); + // KTU ctx.setProperty(WindowNo+"|"+context, stringValue); getLogger().finer("Context("+WindowNo+") " + context + "==" + stringValue); } @@ -815,13 +829,28 @@ public final class Env return new Timestamp(System.currentTimeMillis()); } + // BUG:3075946 KTU - Fix Thai Date + /* // timestamp requires time if (s.trim().length() == 10) s = s.trim() + " 00:00:00.0"; else if (s.indexOf('.') == -1) s = s.trim() + ".0"; - return Timestamp.valueOf(s); + return Timestamp.valueOf(s);*/ + + Date date = null; + try { + date = DisplayType.getTimestampFormat_Default().parse(s); + } catch (ParseException e) { + e.printStackTrace(); + return null; + } + + Timestamp timeStampDate = new Timestamp(date.getTime()); + + return timeStampDate; + // KTU } // getContextAsDate /** diff --git a/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calendar.java b/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calendar.java index 9887ee72e7..52a38ebef5 100644 --- a/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calendar.java +++ b/org.adempiere.ui.swing/src/org/compiere/grid/ed/Calendar.java @@ -34,7 +34,6 @@ import java.sql.Time; import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import java.util.logging.Level; @@ -75,7 +74,7 @@ public class Calendar extends CDialog /** * */ - private static final long serialVersionUID = -1547404617639717922L; + private static final long serialVersionUID = 6482995795697809468L; /** * Mimimum Constructor for Date editor @@ -115,7 +114,10 @@ public class Calendar extends CDialog /** Display Type */ private int m_displayType; /** The Date */ - private GregorianCalendar m_calendar; + // BUG:3075946KTU - fix Thai Date + //private GregorianCalendar m_calendar; + private java.util.Calendar m_calendar; + // KTU /** Is there a PM format */ private boolean m_hasAM_PM = false; // @@ -148,7 +150,10 @@ public class Calendar extends CDialog private CPanel mainPanel = new CPanel(); private CPanel monthPanel = new CPanel(); private CComboBox cMonth = new CComboBox(); - private JSpinner cYear = new JSpinner(new SpinnerNumberModel(2000, 1900,2100,1)); + // BUG:3075946 KTU - Fix Thai Date + //private JSpinner cYear = new JSpinner(new SpinnerNumberModel(2000, 1900,2100,1)); + private JSpinner cYear = new JSpinner(new SpinnerNumberModel(2000, 1900, 3000, 1)); + // KTU private BorderLayout mainLayout = new BorderLayout(); private CPanel dayPanel = new CPanel(); private GridLayout dayLayout = new GridLayout(); @@ -269,7 +274,10 @@ public class Calendar extends CDialog */ private void loadData (Timestamp startTS) { - m_calendar = new GregorianCalendar(Language.getLoginLanguage().getLocale()); + // BUG:3075946 KTU - Fix Thai Date + //m_calendar = new GregorianCalendar(Language.getLoginLanguage().getLocale()); + m_calendar = java.util.Calendar.getInstance(Language.getLoginLanguage().getLocale()); + // KTU if (startTS == null) m_calendar.setTimeInMillis(System.currentTimeMillis()); else