some needed date-converters
authortob <tob>
Fri, 15 Feb 2002 20:39:42 +0000 (20:39 +0000)
committertob <tob>
Fri, 15 Feb 2002 20:39:42 +0000 (20:39 +0000)
source/mir/misc/StringUtil.java

index a3c70da..dddaf65 100755 (executable)
@@ -33,6 +33,22 @@ public final class StringUtil {
   }
 
   /**
+   * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
+   * @param theDate
+   * @return 12-ziffriger String (yyyymmdd)
+   */
+
+  public static final String date2webdbDateTime (GregorianCalendar theDate) {
+    StringBuffer webdbDate = new StringBuffer();
+    webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
+    webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
+    webdbDate.append(pad2(theDate.get(Calendar.DATE)));
+    webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
+    webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
+    return  webdbDate.toString();
+  }
+
+  /**
    * wandelt Calendar in dd.mm.yyyy / hh.mm um
    * @param theDate
    * @return String mit (dd.mm.yyyy / hh.mm um)
@@ -99,6 +115,57 @@ public final class StringUtil {
     return returnDate.toString();
   }
 
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to yyyy
+   */
+  public static String dateToYear (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+
+      returnDate.append(date.substring(0,4));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to [m]m
+   */
+  public static String dateToMonth (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+                 if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
+      else returnDate.append(date.substring(6,7));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to [d]d
+   */
+  public static String dateToDayOfMonth (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+                 if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
+      else returnDate.append(date.substring(9,10));
+    }
+    return returnDate.toString();
+  }
+
+  /**
+   * converts string from format: yyyy-mm-dd__hh:mm:ss.d
+   * to hh:mm
+   */
+  public static String dateToTime (String date) {
+    StringBuffer returnDate = new StringBuffer();
+    if (date!=null) {
+      returnDate.append(date.substring(11,16));
+    }
+    return returnDate.toString();
+  }
+
 
   /**
    * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
@@ -241,7 +308,7 @@ public final class StringUtil {
     }
   }
 
+
 
 
   /**
@@ -896,7 +963,7 @@ public final class StringUtil {
       } else {
         title = removeHTMLTags(title);
         return regex.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">"+title+"</a>");
-      } 
+      }
     } catch(REException ex){
       return null;
     }
@@ -933,7 +1000,7 @@ public final class StringUtil {
         return regex.substituteAll(haystack,"<img hspace=\"10\" vspace=\"6\" align=\"left\" src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\""+title+"\"/>&#160;<br><i>"+title+"</i>");
       } else {
         return regex.substituteAll(haystack,"<img hspace=\"10\" vspace=\"6\" align=\"left\" src=\"$0\" width=\""+width+"\" height=\""+height+"\" alt=\"\"/>&#160;");
-      } 
+      }
     } catch(REException ex){
       return null;
     }
@@ -958,7 +1025,7 @@ public final class StringUtil {
       return null;
     }
   }
-  
+
     /**
      * this method deletes all html tags
      *
@@ -988,24 +1055,24 @@ try {
       String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
       String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";
       String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
-      
+
       // kill all the bad tags that have attributes
       String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
       RE regex = new RE(s,RE.REG_ICASE);
       haystack = regex.substituteAll(haystack,"");
-      
+
       // kill all the bad tags that are attributeless
       regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
       haystack = regex.substituteAll(haystack,"");
-      
+
       // kill all the tags which have a javascript attribute like onLoad
       regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
       haystack = regex.substituteAll(haystack,"");
-      
+
       // kill all the tags which include a url to an unacceptable protocol
       regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
       haystack = regex.substituteAll(haystack,"");
-      
+
       return haystack;
     } catch(REException ex){
       ex.printStackTrace();