From 29be609adb8377a6535926fc33c9f5906a4ec696 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 17 Sep 2007 15:27:39 +0000
Subject: [PATCH] This commit is for supporting of task scheduling in the future (right now tasks can only be scheduled to start immediately) for tasks that support scheduling.  Start time is specified by including -t/--startTime along with a date string of format 'YYYYMMDDhhmmss'.

---
 opends/src/server/org/opends/server/util/StaticUtils.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 54 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/util/StaticUtils.java b/opends/src/server/org/opends/server/util/StaticUtils.java
index 80dfa0f..1ddfee9 100644
--- a/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -41,6 +41,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.nio.ByteBuffer;
 import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
@@ -48,6 +49,8 @@
 import java.util.Map;
 import java.util.RandomAccess;
 import java.util.StringTokenizer;
+import java.util.Date;
+import java.util.TimeZone;
 
 import org.opends.messages.Message;
 import org.opends.messages.MessageBuilder;
@@ -66,7 +69,6 @@
 import org.opends.server.types.RDN;
 
 
-
 /**
  * This class defines a number of static utility methods that may be used
  * throughout the server.  Note that because of the frequency with which these
@@ -3952,5 +3954,56 @@
     }
   }
 
+  /**
+   * Converts a string representing a time in "yyyyMMddHHmmss.SSS'Z'" or
+   * "yyyyMMddHHmmss" to a <code>Date</code>.
+   *
+   * @param timeStr string formatted appropriately
+   * @return Date object; null if <code>timeStr</code> is null
+   * @throws ParseException if there was a problem converting the string to
+   *         a <code>Date</code>.
+   */
+  static public Date parseDateTimeString(String timeStr) throws ParseException
+  {
+    Date dateTime = null;
+    if (timeStr != null)
+    {
+      if (timeStr.endsWith("Z"))
+      {
+        SimpleDateFormat dateFormat =
+            new SimpleDateFormat(DATE_FORMAT_GENERALIZED_TIME);
+        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+        dateFormat.setLenient(true);
+        dateTime = dateFormat.parse(timeStr);
+      }
+      else
+      {
+        SimpleDateFormat dateFormat =
+            new SimpleDateFormat(DATE_FORMAT_COMPACT_LOCAL_TIME);
+        dateFormat.setLenient(true);
+        dateTime = dateFormat.parse(timeStr);
+      }
+    }
+    return dateTime;
+  }
+
+  /**
+   * Formats a Date to String representation in "yyyyMMddHHmmss'Z'".
+   *
+   * @param date to format; null if <code>date</code> is null
+   * @return string representation of the date
+   */
+  static public String formatDateTimeString(Date date)
+  {
+    String timeStr = null;
+    if (date != null)
+    {
+      SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME);
+      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+      timeStr = dateFormat.format(date);
+    }
+    return timeStr;
+  }
+
 }
 

--
Gitblit v1.10.0