From fb660c3100217b3211c0ea23ef7aefcdffa2b1e2 Mon Sep 17 00:00:00 2001 From: Nicolas Micoud Date: Thu, 11 Oct 2012 10:13:13 +0200 Subject: [PATCH] IDEMPIERE-459 - Add Timestamp Value to MSysConfig --- .../src/org/compiere/model/MSysConfig.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 9c03fa6de5..3ae985b7a2 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -16,6 +16,9 @@ package org.compiere.model; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Properties; import java.util.logging.Level; @@ -463,6 +466,71 @@ public class MSysConfig extends X_AD_SysConfig return Boolean.valueOf(s).booleanValue(); } + /** + * Get system configuration property of type Timestamp + * @param Name + * @return Timestamp + */ + public static Timestamp getTimestampValue(String Name) + { + return getTimestampValue(Name, null); + } + + /** + * Get system configuration property of type Timestamp + * @param Name + * @param defaultValue + * @return Timestamp + */ + public static Timestamp getTimestampValue(String Name, Timestamp defaultValue) + { + return getTimestampValue(Name, defaultValue, 0); + } + + /** + * Get system configuration property of type Timestamp + * @param Name + * @param defaultValue + * @param Client ID + * @return Timestamp + */ + public static Timestamp getTimestampValue(String Name, Timestamp defaultValue, int AD_Client_ID) + { + return getTimestampValue(Name, defaultValue, AD_Client_ID, 0); + } + + /** + * Get system configuration property of type Timestamp + * @param Name + * @param defaultValue + * @param Client ID + * @param Organization ID + * @return Timestamp + */ + public static Timestamp getTimestampValue(String Name, Timestamp defaultValue, int AD_Client_ID, int AD_Org_ID) + { + String text = getValue(Name, null, AD_Client_ID, AD_Org_ID); + if (text !=null) + return convertStringToTimestamp(text); + + return defaultValue; + } + /** convert a string to a timestamp */ + static Timestamp convertStringToTimestamp(String text) + { + Timestamp dt = null; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + java.util.Date date = null; + + try { + date = sdf.parse(text); + dt = new Timestamp(date.getTime()); + } catch (ParseException e) { + e.printStackTrace(); + } + return dt; + } + /************************************************************************** * Before Save * @param newRecord