[Schmitzm-commits] r1078 - trunk/src/schmitzm/lang/tree

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Oct 6 22:53:32 CEST 2010


Author: mojays
Date: 2010-10-06 22:53:31 +0200 (Wed, 06 Oct 2010)
New Revision: 1078

Modified:
   trunk/src/schmitzm/lang/tree/OperationTree.java
   trunk/src/schmitzm/lang/tree/OperationTreeParser.java
Log:
OperationTree/Parser: new functions millis(.) and datestr(.) to deal with dates

Modified: trunk/src/schmitzm/lang/tree/OperationTree.java
===================================================================
--- trunk/src/schmitzm/lang/tree/OperationTree.java	2010-10-05 10:08:07 UTC (rev 1077)
+++ trunk/src/schmitzm/lang/tree/OperationTree.java	2010-10-06 20:53:31 UTC (rev 1078)
@@ -29,6 +29,8 @@
  ******************************************************************************/
 package schmitzm.lang.tree;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Random;
 import java.util.regex.Pattern;
 
@@ -62,6 +64,8 @@
  *         <li>Test auf regulaeren Ausdruck: {@code "regex(expression,regular expr)"}</li>
  *         <li>n-tes Ergebnis eines {@linkplain String#split(String) String-Splits} ueber regulaeren Ausdruck: {@code "split(expression,regular expr,n)"}</li>
  *         <li>String-Ersetzung: {@code "replAll(expression,pattern expr,repl expr)"}</li>
+ *         <li>Umwandung eines Datums-String in Milli-Sekunden: {@code millis(string expr, format string expr)}
+ *         <li>Umwandung von Milli-Sekunden in einen Datums-String: {@code dateStr(num expr, format string expr)}
  *       </ul></li>
  *   <li>{@link UnaryOperatorNode}: Innere Knoten, die fuer einen 1-stelligen
  *       Operator auf dem <i>linken</i> Sohn stehen:
@@ -410,8 +414,27 @@
 //        boolean ret = Pattern.matches(operand2.toString(), operand1.toString());
         return Pattern.matches(operand2.toString(), operand1.toString()) ? 1 : 0;
       }
+      if ( operator.equals("MILLIS") ) {
+        SimpleDateFormat formatter = new SimpleDateFormat(operand2.toString());
+        try {
+          Date date = formatter.parse(operand1.toString());
+          return date.getTime();
+        } catch (Exception err) {
+          throw new UnsupportedOperationException(err);
+        }
+      }
     }
 
+    // Long/String-Operationen
+    if ( operand1 instanceof Number && operand2 instanceof String ) {
+      if ( operator.equals("DATESTR") ) {
+        SimpleDateFormat formatter = new SimpleDateFormat(operand2.toString());
+        long millis = ((Number)operand1).longValue();
+        Date date   = new Date(millis);
+        return formatter.format(date);
+      }
+    }
+
     String op1Class = (operand1 != null) ? operand1.getClass().getSimpleName() : null;
     String op2Class = (operand2 != null) ? operand2.getClass().getSimpleName() : null;
     throw new UnsupportedOperationException( LangUtil.RESOURCE.getString("OperationTree.err.UnknownOperator",operator+" ("+op1Class+", "+op2Class+")") );

Modified: trunk/src/schmitzm/lang/tree/OperationTreeParser.java
===================================================================
--- trunk/src/schmitzm/lang/tree/OperationTreeParser.java	2010-10-05 10:08:07 UTC (rev 1077)
+++ trunk/src/schmitzm/lang/tree/OperationTreeParser.java	2010-10-06 20:53:31 UTC (rev 1078)
@@ -91,6 +91,8 @@
  *          <li>String-Konkatenation: {@code "+"}</li>
  *          <li>Test auf regulaeren Ausdruck: {@code "regex(expression,regular expr)"}</li>
  *          <li>n-tes Ergebnis eines {@linkplain String#split(String) String-Splits} ueber regulaeren Ausdruck: {@code "split(expression,regular expr,n)"}</li>
+ *          <li>Umwandung eines Datums-String in Milli-Sekunden: {@code millis(string expr, format string expr)}
+ *          <li>Umwandung von Milli-Sekunden in einen Datums-String: {@code dateStr(num expr, format string expr)}
  *       </ul></li>
  *   <li>den mehr-stelligen Zeichenketten-Operatoren: {@link MultiParamOperatorNode}
  *       <ul>
@@ -980,6 +982,22 @@
       return new OperationTree.MultiParamOperatorNode(token,null,splitParam);
     }
 
+    // MILLIS(string,formatexpr) = Umwandung von Datums-String (in angebenen Format) in Millisekunden
+    if ( token.equals("millis") ) {
+      // Parameter fuer MILLIS parsen
+      BinaryTreeNode[] millisParam = parseFunctionParameters("MILLIS",2);
+      // Baum fuer MILLIS
+      return new OperationTree.OperatorNode(token,millisParam[0],millisParam[1]);
+    }
+
+    // DATE(num,formatexpr) = Umwandung von Millisekunden in Datums-String (in angebenen Format)
+    if ( token.equals("datestr") ) {
+      // Parameter fuer MILLIS parsen
+      BinaryTreeNode[] millisParam = parseFunctionParameters("DATESTR",2);
+      // Baum fuer DATESTR
+      return new OperationTree.OperatorNode(token,millisParam[0],millisParam[1]);
+    }
+
     // SUBSTR(string,startPos_inkl,endPos_exkl) = Teil-String
     if ( token.equals("substr") ) {
       // Parameter fuer SUBSTR parsen



More information about the Schmitzm-commits mailing list