[Bedework-commit] calendarapi r744 - in trunk: calFacade/src/org/bedework/calfacade calFacade/src/org/bedework/calfacade/base calFacade/src/org/bedework/calfacade/timezones calFacade/src/org/bedework/calfacade/util calFacade/src/org/bedework/calfacade/util/xml calsvc/src/org/bedework/calsvc mail/src/org/bedework/mail

svnadmin at bedework.org svnadmin at bedework.org
Thu Nov 20 15:11:59 EST 2008


Author: douglm
Date: 2008-11-20 15:11:58 -0500 (Thu, 20 Nov 2008)
New Revision: 744

Added:
   trunk/calFacade/src/org/bedework/calfacade/util/BwDateTimeUtil.java
Removed:
   trunk/calFacade/src/org/bedework/calfacade/util/DateTimeUtil.java
Modified:
   trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java
   trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
   trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java
   trunk/calFacade/src/org/bedework/calfacade/BwResource.java
   trunk/calFacade/src/org/bedework/calfacade/base/BwLastMod.java
   trunk/calFacade/src/org/bedework/calfacade/timezones/CalTimezones.java
   trunk/calFacade/src/org/bedework/calfacade/util/xml/CalDavParseUtil.java
   trunk/calsvc/src/org/bedework/calsvc/Calendars.java
   trunk/calsvc/src/org/bedework/calsvc/Indexing.java
   trunk/calsvc/src/org/bedework/calsvc/TimeZonesStoreImpl.java
   trunk/mail/src/org/bedework/mail/MailUtil.java
Log:
Move a number of date time utility routines out into a shared package

Modified: trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/BwAlarm.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -64,8 +64,10 @@
 import org.bedework.calfacade.base.SummaryEntity;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.util.CalFacadeUtil;
-import org.bedework.calfacade.util.DateTimeUtil;
+import org.bedework.calfacade.util.BwDateTimeUtil;
 
+import edu.rpi.sss.util.DateTimeUtil;
+
 import net.fortuna.ical4j.model.Dur;
 import net.fortuna.ical4j.model.property.Duration;
 import net.fortuna.ical4j.model.property.Trigger;
@@ -843,7 +845,7 @@
           throw new CalFacadeException("No event for alarm " + this);
         }
 
-        dt = dur.getTime(DateTimeUtil.getDate(getEvent().getDtstart()));
+        dt = dur.getTime(BwDateTimeUtil.getDate(getEvent().getDtstart()));
       }
 
       triggerDate = dt;

Modified: trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/BwCalendar.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -62,9 +62,9 @@
 import org.bedework.calfacade.base.CollatableEntity;
 import org.bedework.calfacade.base.PropertiesEntity;
 import org.bedework.calfacade.exc.CalFacadeException;
-import org.bedework.calfacade.util.DateTimeUtil;
 
 import edu.rpi.cmt.access.Acl.CurrentAccess;
+import edu.rpi.sss.util.DateTimeUtil;
 import edu.rpi.sss.util.xml.tagdefs.AppleIcalTags;
 import edu.rpi.sss.util.xml.tagdefs.CaldavTags;
 

Modified: trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/BwDateTime.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -59,8 +59,10 @@
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.timezones.CalTimezones;
 import org.bedework.calfacade.util.CalFacadeUtil;
-import org.bedework.calfacade.util.DateTimeUtil;
 
+import edu.rpi.sss.util.DateTimeUtil;
+import edu.rpi.sss.util.DateTimeUtil.BadDateException;
+
 import java.io.Serializable;
 import java.util.Comparator;
 
@@ -546,25 +548,29 @@
    */
   public void init(boolean dateType, String date, String tzid,
                    TimeZone tz, BwUser tzowner) throws CalFacadeException {
-    if (dateType) {
-      if (!DateTimeUtil.isISODate(date)) {
-        throw new CalFacadeException("org.bedework.datetime.expect.dateonly");
+    try {
+      if (dateType) {
+        if (!DateTimeUtil.isISODate(date)) {
+          throw new CalFacadeException("org.bedework.datetime.expect.dateonly");
+        }
       }
-    }
-    setDateType(dateType);
-    setDtval(date);
-    setTzid(tzid);
-    setTzowner(tzowner);
+      setDateType(dateType);
+      setDtval(date);
+      setTzid(tzid);
+      setTzowner(tzowner);
 
-    if (tzid == null) {
-      if (DateTimeUtil.isISODateTime(date)) {
-        setFloatFlag(true);
-        setDate(date + "Z");
+      if (tzid == null) {
+        if (DateTimeUtil.isISODateTime(date)) {
+          setFloatFlag(true);
+          setDate(date + "Z");
+        }
       }
-    }
 
-    if (!getFloating()) {
-      setDate(CalTimezones.getTimezones().getUtc(date, tzid, tz, tzowner));
+      if (!getFloating()) {
+        setDate(CalTimezones.getTimezones().getUtc(date, tzid, tz, tzowner));
+      }
+    } catch (BadDateException bde) {
+      throw new CalFacadeBadDateException();
     }
   }
 

Modified: trunk/calFacade/src/org/bedework/calfacade/BwResource.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/BwResource.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/BwResource.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -26,9 +26,10 @@
 package org.bedework.calfacade;
 
 import org.bedework.calfacade.base.BwShareableContainedDbentity;
-import org.bedework.calfacade.util.CalFacadeUtil;
-import org.bedework.calfacade.util.DateTimeUtil;
 
+import edu.rpi.sss.util.DateTimeUtil;
+import edu.rpi.sss.util.Util;
+
 import net.fortuna.ical4j.model.DateTime;
 import net.fortuna.ical4j.model.property.LastModified;
 
@@ -276,12 +277,12 @@
       return 0;
     }
 
-    int res = CalFacadeUtil.cmpObjval(getCalendar(), that.getCalendar());
+    int res = Util.cmpObjval(getCalendar(), that.getCalendar());
     if (res != 0) {
       return res;
     }
 
-    return CalFacadeUtil.cmpObjval(getName(), that.getName());
+    return Util.cmpObjval(getName(), that.getName());
   }
 
   public String toString() {

Modified: trunk/calFacade/src/org/bedework/calfacade/base/BwLastMod.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/base/BwLastMod.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/base/BwLastMod.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -28,8 +28,9 @@
 import org.bedework.calfacade.CalFacadeDefs;
 import org.bedework.calfacade.annotations.NoDump;
 import org.bedework.calfacade.annotations.NoWrap;
-import org.bedework.calfacade.util.DateTimeUtil;
 
+import edu.rpi.sss.util.DateTimeUtil;
+
 import net.fortuna.ical4j.model.DateTime;
 import net.fortuna.ical4j.model.property.LastModified;
 

Modified: trunk/calFacade/src/org/bedework/calfacade/timezones/CalTimezones.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/timezones/CalTimezones.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/timezones/CalTimezones.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -28,8 +28,9 @@
 import org.bedework.calfacade.BwUser;
 import org.bedework.calfacade.exc.CalFacadeBadDateException;
 import org.bedework.calfacade.exc.CalFacadeException;
-import org.bedework.calfacade.util.DateTimeUtil;
 
+import edu.rpi.sss.util.DateTimeUtil;
+
 import net.fortuna.ical4j.model.TimeZone;
 import net.fortuna.ical4j.model.component.VTimeZone;
 import net.fortuna.ical4j.util.TimeZones;
@@ -672,49 +673,49 @@
   public synchronized String getUtc(String time, String tzid, TimeZone tz,
                                        BwUser tzowner)
           throws CalFacadeException {
-    //if (debug) {
-    //  trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz);
-    //}
-    if (DateTimeUtil.isISODateTimeUTC(time)) {
-      // Already UTC
-      return time;
-    }
+    try {
+      //if (debug) {
+      //  trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz);
+      //}
+      if (DateTimeUtil.isISODateTimeUTC(time)) {
+        // Already UTC
+        return time;
+      }
 
-    String dateKey = null;
-    HashMap<String, String> cache = null;
+      String dateKey = null;
+      HashMap<String, String> cache = null;
 
-    if ((time.length() == 8) && DateTimeUtil.isISODate(time)) {
-      /* See if we have it cached */
+      if ((time.length() == 8) && DateTimeUtil.isISODate(time)) {
+        /* See if we have it cached */
 
-      if (tzid == null) {
-        cache = defaultDateCache;
-      } else if (tzid.equals(getDefaultTimeZoneId())) {
-        cache = defaultDateCache;
-      } else {
-        cache = dateCaches.get(tzid);
-        if (cache == null) {
-          cache = new HashMap<String, String>();
-          dateCaches.put(tzid, cache);
+        if (tzid == null) {
+          cache = defaultDateCache;
+        } else if (tzid.equals(getDefaultTimeZoneId())) {
+          cache = defaultDateCache;
+        } else {
+          cache = dateCaches.get(tzid);
+          if (cache == null) {
+            cache = new HashMap<String, String>();
+            dateCaches.put(tzid, cache);
+          }
         }
-      }
 
-      String utc = cache.get(time);
+        String utc = cache.get(time);
 
-      if (utc != null) {
-        dateCacheHits++;
-        return utc;
-      }
+        if (utc != null) {
+          dateCacheHits++;
+          return utc;
+        }
 
-      /* Not in the cache - calculate it */
+        /* Not in the cache - calculate it */
 
-      dateCacheMisses++;
-      dateKey = time;
-      time += "T000000";
-    } else if (!DateTimeUtil.isISODateTime(time)) {
-      throw new CalFacadeBadDateException(time);
-    }
+        dateCacheMisses++;
+        dateKey = time;
+        time += "T000000";
+      } else if (!DateTimeUtil.isISODateTime(time)) {
+        throw new CalFacadeBadDateException(time);
+      }
 
-    try {
       boolean tzchanged = false;
 
       /* If we get a null timezone and id we are being asked for the default.
@@ -800,7 +801,7 @@
     } catch (CalFacadeException cfe) {
       throw cfe;
     } catch (Throwable t) {
-      t.printStackTrace();
+      //t.printStackTrace();
       throw new CalFacadeBadDateException(time);
     }
   }

Copied: trunk/calFacade/src/org/bedework/calfacade/util/BwDateTimeUtil.java (from rev 743, trunk/calFacade/src/org/bedework/calfacade/util/DateTimeUtil.java)
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/BwDateTimeUtil.java	                        (rev 0)
+++ trunk/calFacade/src/org/bedework/calfacade/util/BwDateTimeUtil.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -0,0 +1,312 @@
+/* **********************************************************************
+    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.calfacade.util;
+
+import org.bedework.calfacade.BwDateTime;
+import org.bedework.calfacade.BwUser;
+import org.bedework.calfacade.exc.CalFacadeBadDateException;
+import org.bedework.calfacade.exc.CalFacadeException;
+import org.bedework.calfacade.locale.BwLocale;
+import org.bedework.calfacade.timezones.CalTimezones;
+
+import edu.rpi.sss.util.DateTimeUtil;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+
+/** Date and time utilities
+ *
+ * @author Mike Douglass     douglm - rpi.edu
+ *  @version 1.0
+ */
+public class BwDateTimeUtil {
+  private static final DateFormat isoDateTimeUTCFormat =
+      new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
+
+  private static final DateFormat rfcDateTimeUTCFormat =
+    new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
+
+  private static final DateFormat rfc822GMTFormat =
+    new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
+
+  static {
+    isoDateTimeUTCFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
+                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
+    isoDateTimeUTCFormat.setLenient(false);
+
+    rfcDateTimeUTCFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
+                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
+    rfcDateTimeUTCFormat.setLenient(false);
+
+    rfc822GMTFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
+                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
+  }
+
+  private BwDateTimeUtil() {
+  }
+
+  /** Get a java.util.Date object from the value
+   * XXX - this will neeed to be supplied with a tz repository
+   *
+   * @param val
+   * @return Date object representing the date
+   * @throws CalFacadeException
+   */
+  public static Date getDate(BwDateTime val) throws CalFacadeException {
+    String dtval = val.getDtval();
+
+    try {
+      if (val.getDateType()) {
+        return DateTimeUtil.fromISODate(dtval);
+      }
+
+      if (dtval.endsWith("Z")) {
+        return DateTimeUtil.fromISODateTimeUTC(dtval);
+      }
+
+      String tzid = val.getTzid();
+      if (tzid == null) {
+        return DateTimeUtil.fromISODateTime(dtval);
+      }
+
+      return DateTimeUtil.fromISODateTime(dtval,
+                                          CalTimezones.getTz(tzid,
+                                                             val.getTzowner()));
+    } catch (CalFacadeException cfe) {
+      throw cfe;
+    } catch (Throwable t) {
+      throw new CalFacadeBadDateException();
+    }
+  }
+
+  /** Get a date/time object representing the given date and time
+   *
+   * @param date       Java Date object
+   * @return BwDateTime object representing the date
+   * @throws CalFacadeException
+   */
+  public static BwDateTime getDateTime(Date date) throws CalFacadeException {
+    String dtval = DateTimeUtil.isoDateTime(date);
+    return getDateTime(dtval, false, false, false, null, null, null);
+  }
+
+  /** Get a date object representing the given date and flags
+   *
+   * @param date       String iso date or date/time
+   * @param dateOnly
+   * @param UTC
+   * @param floating    boolean true if this is a floating time
+   * @param tzid - String tzid or null for default, UTC or floating.
+   * @param tzowner
+   * @return Date object representing the date
+   * @throws CalFacadeException
+   */
+  public static BwDateTime getDateTime(String date, boolean dateOnly,
+                                       boolean UTC, boolean floating,
+                                       String tzid,
+                                       BwUser tzowner) throws CalFacadeException {
+    return getDateTime(date, dateOnly, UTC, floating, tzid, null, tzowner);
+  }
+
+  /** Get a date object representing the given date and flags
+   *
+   * @param date       String iso date or date/time
+   * @param dateOnly
+   * @param UTC
+   * @param floating    boolean true if this is a floating time
+   * @param tzid - String tzid or null for default, UTC or floating.
+   * @param tz - timezone to use
+   * @param tzowner
+   * @return Date object representing the date
+   * @throws CalFacadeException
+   */
+  public static BwDateTime getDateTime(String date, boolean dateOnly,
+                                       boolean UTC, boolean floating,
+                                       String tzid,
+                                       net.fortuna.ical4j.model.TimeZone tz,
+                                       BwUser tzowner) throws CalFacadeException {
+    try {
+      BwDateTime dtm = new BwDateTime();
+
+      if (dateOnly || UTC || floating) {
+        tzid = null;
+      }
+
+      if (tz != null) {
+        tzid = tz.getID();
+      } else if (tzid != null) {
+        tz = CalTimezones.getTz(tzid, tzowner);
+        if (tz == null) {
+          throw new CalFacadeException(CalFacadeException.unknownTimezone, tzid);
+        }
+      } else if (!UTC && !floating) {
+        // Asking for default
+        tzid = CalTimezones.getDefaultTzid();
+        tz = CalTimezones.getDefaultTz();
+      }
+
+      if (DateTimeUtil.isISODateTimeUTC(date) && !UTC) {
+        // Convert to local time (relative to supplied timezone)
+
+        Date dt = DateTimeUtil.fromISODateTimeUTC(date);
+        date = DateTimeUtil.isoDateTime(dt, tz);
+      }
+
+      dtm.init(dateOnly, date, tzid, tz, tzowner);
+
+      return dtm;
+    } catch (Throwable t) {
+      throw new CalFacadeBadDateException();
+    }
+  }
+
+  /** Get a date object representing the given String UTC date/time
+   *
+   * @param date
+   * @return BwDateTime object representing the date
+   * @throws CalFacadeException
+   */
+  public static BwDateTime getDateTimeUTC(String date) throws CalFacadeException {
+    BwDateTime dtm = new BwDateTime();
+
+    dtm.initUTC(false, date);
+
+    return dtm;
+  }
+
+  /** */
+  public static class DatePeriod {
+    /** ISO */
+    public BwDateTime start;
+    /** ISO */
+    public BwDateTime end;
+  }
+
+  /** Get a date/time range given by the rfc formatted parameters and limited to
+   * the given max range
+   *
+   * @param start
+   * @param end
+   * @param defaultField
+   * @param defaultVal
+   * @param maxField
+   * @param maxVal
+   * @return DatePeriod or null for bad request
+   * @throws CalFacadeException
+   */
+  public static DatePeriod getPeriod(String start, String end,
+                               int defaultField, int defaultVal,
+                               int maxField,
+                               int maxVal) throws CalFacadeException {
+    Locale loc = BwLocale.getLocale();
+    Calendar startCal = Calendar.getInstance(loc);
+    startCal.set(Calendar.HOUR_OF_DAY, 0);
+    startCal.set(Calendar.MINUTE, 0);
+    startCal.set(Calendar.SECOND, 0);
+
+    Calendar endCal = Calendar.getInstance(loc);
+    endCal.set(Calendar.HOUR_OF_DAY, 0);
+    endCal.set(Calendar.MINUTE, 0);
+    endCal.set(Calendar.SECOND, 0);
+
+    if (start != null) {
+      startCal.setTime(fromDate(start));
+    }
+
+    if (end == null) {
+      endCal.add(defaultField, defaultVal);
+    } else {
+      endCal.setTime(fromDate(end));
+    }
+
+    // Don't allow more than a month
+    Calendar check = Calendar.getInstance(loc);
+    check.setTime(startCal.getTime());
+    check.add(maxField, maxVal);
+
+    if (check.before(endCal)) {
+      return null;
+    }
+
+    DatePeriod dp = new DatePeriod();
+
+    dp.start = BwDateTimeUtil.getDateTime(
+               DateTimeUtil.isoDateTime(startCal.getTime()),
+                                        false,
+                                        false,
+                                        false,   // floating
+                                        null,   // tzid
+                                        null);  // tzowner
+    dp.end = BwDateTimeUtil.getDateTime(
+             DateTimeUtil.isoDateTime(endCal.getTime()),
+                                      false,
+                                      false,
+                                      false,   // floating
+                                      null,   // tzid
+                                      null);   // tzowner
+
+    return dp;
+  }
+
+  private static Date fromDate(String dt) throws CalFacadeException {
+    try {
+      if (dt == null) {
+        return null;
+      }
+
+      if (dt.indexOf("T") > 0) {
+        return fromDateTime(dt);
+      }
+
+      if (dt.indexOf("-") < 0) {
+        return DateTimeUtil.fromISODate(dt);
+      }
+
+      return DateTimeUtil.fromRfcDate(dt);
+    } catch (Throwable t) {
+      throw new CalFacadeBadDateException();
+    }
+  }
+
+  private static Date fromDateTime(String dt) throws CalFacadeException {
+    try {
+      if (dt == null) {
+        return null;
+      }
+
+      if (dt.indexOf("-") < 0) {
+        return DateTimeUtil.fromISODateTimeUTC(dt);
+      }
+
+      return DateTimeUtil.fromRfcDateTimeUTC(dt);
+    } catch (Throwable t) {
+      throw new CalFacadeBadDateException();
+    }
+  }
+}


Property changes on: trunk/calFacade/src/org/bedework/calfacade/util/BwDateTimeUtil.java
___________________________________________________________________
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + LF

Deleted: trunk/calFacade/src/org/bedework/calfacade/util/DateTimeUtil.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/DateTimeUtil.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/util/DateTimeUtil.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -1,688 +0,0 @@
-/* **********************************************************************
-    Copyright 2007 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
-    Redistribution and use of this distribution in source and binary forms,
-    with or without modification, are permitted provided that:
-       The above copyright notice and this permission notice appear in all
-        copies and supporting documentation;
-
-        The name, identifiers, and trademarks of Rensselaer Polytechnic
-        Institute are not used in advertising or publicity without the
-        express prior written permission of Rensselaer Polytechnic Institute;
-
-    DISCLAIMER: The software is distributed" AS IS" without any express or
-    implied warranty, including but not limited to, any implied warranties
-    of merchantability or fitness for a particular purpose or any warrant)'
-    of non-infringement of any current or pending patent rights. The authors
-    of the software make no representations about the suitability of this
-    software for any particular purpose. The entire risk as to the quality
-    and performance of the software is with the user. Should the software
-    prove defective, the user assumes the cost of all necessary servicing,
-    repair or correction. In particular, neither Rensselaer Polytechnic
-    Institute, nor the authors of the software are liable for any indirect,
-    special, consequential, or incidental damages related to the software,
-    to the maximum extent the law permits.
-*/
-package org.bedework.calfacade.util;
-
-import org.bedework.calfacade.BwDateTime;
-import org.bedework.calfacade.BwUser;
-import org.bedework.calfacade.exc.CalFacadeBadDateException;
-import org.bedework.calfacade.exc.CalFacadeException;
-import org.bedework.calfacade.locale.BwLocale;
-import org.bedework.calfacade.timezones.CalTimezones;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.TimeZone;
-
-/** Date and time utilities
- *
- * @author Mike Douglass     douglm - rpi.edu
- *  @version 1.0
- */
-public class DateTimeUtil {
-  private static final DateFormat isoDateFormat =
-      new SimpleDateFormat("yyyyMMdd");
-
-  private static final DateFormat rfcDateFormat =
-    new SimpleDateFormat("yyyy'-'MM'-'dd");
-
-  private static final DateFormat isoDateTimeFormat =
-      new SimpleDateFormat("yyyyMMdd'T'HHmmss");
-
-  private static final DateFormat rfcDateTimeFormat =
-    new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
-
-  private static final DateFormat isoDateTimeTZFormat =
-      new SimpleDateFormat("yyyyMMdd'T'HHmmss");
-
-  private static final DateFormat rfcDateTimeTZFormat =
-      new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
-
-  private static final DateFormat isoDateTimeUTCTZFormat =
-      new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
-
-//  private static final DateFormat rfcDateTimeUTCTZFormat =
-  //  new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
-
-  private static final DateFormat isoDateTimeUTCFormat =
-      new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
-
-  private static final DateFormat rfcDateTimeUTCFormat =
-    new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
-
-  private static final DateFormat rfc822GMTFormat =
-    new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
-
-  static {
-    isoDateTimeUTCFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
-                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
-    isoDateTimeUTCFormat.setLenient(false);
-
-    rfcDateTimeUTCFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
-                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
-    rfcDateTimeUTCFormat.setLenient(false);
-
-    rfc822GMTFormat.setTimeZone(net.fortuna.ical4j.model.TimeZone.getTimeZone(
-                                 net.fortuna.ical4j.util.TimeZones.UTC_ID));
-  }
-
-  private DateTimeUtil() {
-  }
-
-  /**
-   * @return Date value for yesterday.
-   */
-  public static Date yesterday() {
-    Calendar cal = Calendar.getInstance();
-    cal.add(Calendar.DATE, -1);
-
-    return cal.getTime();
-  }
-
-  /** Turn Date into "yyyyMMdd"
-   *
-   * @param val date
-   * @return String "yyyyMMdd"
-   */
-  public static String isoDate(Date val) {
-    synchronized (isoDateFormat) {
-      return isoDateFormat.format(val);
-    }
-  }
-
-  /** Turn Now into "yyyyMMdd"
-   *
-   * @return String "yyyyMMdd"
-   */
-  public static String isoDate() {
-    return isoDate(new Date());
-  }
-
-  /** Turn Date into "yyyy-MM-dd"
-   *
-   * @param val date
-   * @return String "yyyy-MM-dd"
-   */
-  public static String rfcDate(Date val) {
-    synchronized (rfcDateFormat) {
-      return rfcDateFormat.format(val);
-    }
-  }
-
-  /** Turn Now into "yyyy-MM-dd"
-   *
-   * @return String "yyyy-MM-dd"
-   */
-  public static String rfcDate() {
-    return rfcDate(new Date());
-  }
-
-  /** Turn Date into "yyyyMMddTHHmmss"
-   *
-   * @param val date
-   * @return String "yyyyMMddTHHmmss"
-   */
-  public static String isoDateTime(Date val) {
-    synchronized (isoDateTimeFormat) {
-      return isoDateTimeFormat.format(val);
-    }
-  }
-
-  /** Get Now as "yyyyMMddTHHmmss"
-   *
-   * @return String "yyyyMMddTHHmmss"
-   */
-  public static String isoDateTime() {
-    return  isoDateTime(new Date());
-  }
-
-  /** Turn Date into "yyyyMMddTHHmmss" for a given timezone
-   *
-   * @param val date
-   * @param tz TimeZone
-   * @return String "yyyyMMddTHHmmss"
-   */
-  public static String isoDateTime(Date val, TimeZone tz) {
-    synchronized (isoDateTimeTZFormat) {
-      isoDateTimeTZFormat.setTimeZone(tz);
-      return isoDateTimeTZFormat.format(val);
-    }
-  }
-
-  /** Turn Date into "yyyy-MM-ddTHH:mm:ss"
-   *
-   * @param val date
-   * @return String "yyyy-MM-ddTHH:mm:ss"
-   */
-  public static String rfcDateTime(Date val) {
-    synchronized (rfcDateTimeFormat) {
-      return rfcDateTimeFormat.format(val);
-    }
-  }
-
-  /** Get Now as "yyyy-MM-ddTHH:mm:ss"
-   *
-   * @return String "yyyy-MM-ddTHH:mm:ss"
-   */
-  public static String rfcDateTime() {
-    return  rfcDateTime(new Date());
-  }
-
-  /** Turn Date into "yyyy-MM-ddTHH:mm:ss" for a given timezone
-   *
-   * @param val date
-   * @param tz TimeZone
-   * @return String "yyyy-MM-ddTHH:mm:ss"
-   */
-  public static String rfcDateTime(Date val, TimeZone tz) {
-    synchronized (rfcDateTimeTZFormat) {
-      rfcDateTimeTZFormat.setTimeZone(tz);
-      return rfcDateTimeTZFormat.format(val);
-    }
-  }
-
-  /** Turn Date into "yyyyMMddTHHmmssZ"
-   *
-   * @param val date
-   * @return String "yyyyMMddTHHmmssZ"
-   */
-  public static String isoDateTimeUTC(Date val) {
-    synchronized (isoDateTimeUTCFormat) {
-      return isoDateTimeUTCFormat.format(val);
-    }
-  }
-
-  /** Turn Date into "yyyy-MM-ddTHH:mm:ssZ"
-   *
-   * @param val date
-   * @return String "yyyy-MM-ddTHH:mm:ssZ"
-   */
-  public static String rfcDateTimeUTC(Date val) {
-    synchronized (rfcDateTimeUTCFormat) {
-      return rfcDateTimeUTCFormat.format(val);
-    }
-  }
-
-  /** Turn Date into "???"
-   *
-   * @param val date
-   * @return String "???"
-   */
-  public static String rfc822Date(Date val) {
-    synchronized (rfc822GMTFormat) {
-      return rfc822GMTFormat.format(val);
-    }
-  }
-
-  /** Get Date from "yyyyMMdd"
-   *
-   * @param val String "yyyyMMdd"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromISODate(String val) throws CalFacadeException {
-    try {
-      synchronized (isoDateFormat) {
-        return isoDateFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyy-MM-dd"
-   *
-   * @param val String "yyyy-MM-dd"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromRfcDate(String val) throws CalFacadeException {
-    try {
-      synchronized (rfcDateFormat) {
-        return rfcDateFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyyMMddThhmmss"
-   *
-   * @param val String "yyyyMMddThhmmss"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromISODateTime(String val) throws CalFacadeException {
-    try {
-      synchronized (isoDateTimeFormat) {
-        return isoDateTimeFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyy-MM-ddThh:mm:ss"
-   *
-   * @param val String "yyyy-MM-ddThh:mm:ss"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromRfcDateTime(String val) throws CalFacadeException {
-    try {
-      synchronized (rfcDateTimeFormat) {
-        return rfcDateTimeFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyyMMddThhmmss" with timezone
-   *
-   * @param val String "yyyyMMddThhmmss"
-   * @param tz TimeZone
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromISODateTime(String val,
-                                     TimeZone tz) throws CalFacadeException {
-    try {
-      synchronized (isoDateTimeTZFormat) {
-        isoDateTimeTZFormat.setTimeZone(tz);
-        return isoDateTimeTZFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyy-MM-ddThh:mm:ss" with timezone
-   *
-   * @param val String "yyyy-ddThh:mm:ss"
-   * @param tz TimeZone
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromRfcDateTime(String val,
-                                     TimeZone tz) throws CalFacadeException {
-    try {
-      synchronized (rfcDateTimeTZFormat) {
-        rfcDateTimeTZFormat.setTimeZone(tz);
-        return rfcDateTimeTZFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyyMMddThhmmssZ" with timezone
-   *
-   * @param val String "yyyyMMddThhmmssZ"
-   * @param tz TimeZone
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromISODateTimeUTC(String val,
-                                        TimeZone tz) throws CalFacadeException {
-    try {
-      synchronized (isoDateTimeUTCTZFormat) {
-        isoDateTimeUTCTZFormat.setTimeZone(tz);
-        return isoDateTimeUTCTZFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyyMMddThhmmssZ"
-   *
-   * @param val String "yyyyMMddThhmmssZ"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromISODateTimeUTC(String val) throws CalFacadeException {
-    try {
-      synchronized (isoDateTimeUTCFormat) {
-        return isoDateTimeUTCFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get Date from "yyyy-MM-ddThh:mm:ssZ"
-   *
-   * @param val String "yyyy-MM-ddThh:mm:ssZ"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static Date fromRfcDateTimeUTC(String val) throws CalFacadeException {
-    try {
-      synchronized (rfcDateTimeUTCFormat) {
-        return rfcDateTimeUTCFormat.parse(val);
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get RFC822 form from "yyyyMMddThhmmssZ"
-   *
-   * @param val String "yyyyMMddThhmmssZ"
-   * @return Date
-   * @throws CalFacadeException
-   */
-  public static String fromISODateTimeUTCtoRfc822(String val) throws CalFacadeException {
-    try {
-      synchronized (isoDateTimeUTCFormat) {
-        return rfc822Date(isoDateTimeUTCFormat.parse(val));
-      }
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Check Date is "yyyyMMdd"
-   *
-   * @param val String to check
-   * @return boolean
-   * @throws CalFacadeException
-   */
-  public static boolean isISODate(String val) throws CalFacadeException {
-    try {
-      if (val.length() != 8) {
-        return false;
-      }
-      fromISODate(val);
-      return true;
-    } catch (Throwable t) {
-      return false;
-    }
-  }
-
-  /** Check Date is "yyyyMMddThhmmddZ"
-   *
-   * @param val String to check
-   * @return boolean
-   * @throws CalFacadeException
-   */
-  public static boolean isISODateTimeUTC(String val) throws CalFacadeException {
-    try {
-      if (val.length() != 16) {
-        return false;
-      }
-      fromISODateTimeUTC(val);
-      return true;
-    } catch (Throwable t) {
-      return false;
-    }
-  }
-
-  /** Check Date is "yyyyMMddThhmmdd"
-   *
-   * @param val String to check
-   * @return boolean
-   * @throws CalFacadeException
-   */
-  public static boolean isISODateTime(String val) throws CalFacadeException {
-    try {
-      if (val.length() != 15) {
-        return false;
-      }
-      fromISODateTime(val);
-      return true;
-    } catch (Throwable t) {
-      return false;
-    }
-  }
-
-  /** Get a java.util.Date object from the value
-   * XXX - this will neeed to be supplied with a tz repository
-   *
-   * @param val
-   * @return Date object representing the date
-   * @throws CalFacadeException
-   */
-  public static Date getDate(BwDateTime val) throws CalFacadeException {
-    String dtval = val.getDtval();
-
-    try {
-      if (val.getDateType()) {
-        return fromISODate(dtval);
-      }
-
-      if (dtval.endsWith("Z")) {
-        return fromISODateTimeUTC(dtval);
-      }
-
-      String tzid = val.getTzid();
-      if (tzid == null) {
-        return fromISODateTime(dtval);
-      }
-
-      return fromISODateTime(dtval,
-                             CalTimezones.getTz(tzid, val.getTzowner()));
-    } catch (CalFacadeException cfe) {
-      throw cfe;
-    } catch (Throwable t) {
-      throw new CalFacadeBadDateException();
-    }
-  }
-
-  /** Get a date/time object representing the given date and time
-   *
-   * @param date       Java Date object
-   * @return BwDateTime object representing the date
-   * @throws CalFacadeException
-   */
-  public static BwDateTime getDateTime(Date date) throws CalFacadeException {
-    String dtval = isoDateTime(date);
-    return getDateTime(dtval, false, false, false, null, null, null);
-  }
-
-  /** Get a date object representing the given date and flags
-   *
-   * @param date       String iso date or date/time
-   * @param dateOnly
-   * @param UTC
-   * @param floating    boolean true if this is a floating time
-   * @param tzid - String tzid or null for default, UTC or floating.
-   * @param tzowner
-   * @return Date object representing the date
-   * @throws CalFacadeException
-   */
-  public static BwDateTime getDateTime(String date, boolean dateOnly,
-                                       boolean UTC, boolean floating,
-                                       String tzid,
-                                       BwUser tzowner) throws CalFacadeException {
-    return getDateTime(date, dateOnly, UTC, floating, tzid, null, tzowner);
-  }
-
-  /** Get a date object representing the given date and flags
-   *
-   * @param date       String iso date or date/time
-   * @param dateOnly
-   * @param UTC
-   * @param floating    boolean true if this is a floating time
-   * @param tzid - String tzid or null for default, UTC or floating.
-   * @param tz - timezone to use
-   * @param tzowner
-   * @return Date object representing the date
-   * @throws CalFacadeException
-   */
-  public static BwDateTime getDateTime(String date, boolean dateOnly,
-                                       boolean UTC, boolean floating,
-                                       String tzid,
-                                       net.fortuna.ical4j.model.TimeZone tz,
-                                       BwUser tzowner) throws CalFacadeException {
-    BwDateTime dtm = new BwDateTime();
-
-    if (dateOnly || UTC || floating) {
-      tzid = null;
-    }
-
-    if (tz != null) {
-      tzid = tz.getID();
-    } else if (tzid != null) {
-      tz = CalTimezones.getTz(tzid, tzowner);
-      if (tz == null) {
-        throw new CalFacadeException(CalFacadeException.unknownTimezone, tzid);
-      }
-    } else if (!UTC && !floating) {
-      // Asking for default
-      tzid = CalTimezones.getDefaultTzid();
-      tz = CalTimezones.getDefaultTz();
-    }
-
-    if (isISODateTimeUTC(date) && !UTC) {
-      // Convert to local time (relative to supplied timezone)
-
-      Date dt = fromISODateTimeUTC(date);
-      date = isoDateTime(dt, tz);
-    }
-
-    dtm.init(dateOnly, date, tzid, tz, tzowner);
-
-    return dtm;
-  }
-
-  /** Get a date object representing the given String UTC date/time
-   *
-   * @param date
-   * @return BwDateTime object representing the date
-   * @throws CalFacadeException
-   */
-  public static BwDateTime getDateTimeUTC(String date) throws CalFacadeException {
-    BwDateTime dtm = new BwDateTime();
-
-    dtm.initUTC(false, date);
-
-    return dtm;
-  }
-
-  /** */
-  public static class DatePeriod {
-    /** ISO */
-    public BwDateTime start;
-    /** ISO */
-    public BwDateTime end;
-  }
-
-  /** Get a date/time range given by the rfc formatted parameters and limited to
-   * the given max range
-   *
-   * @param start
-   * @param end
-   * @param defaultField
-   * @param defaultVal
-   * @param maxField
-   * @param maxVal
-   * @return DatePeriod or null for bad request
-   * @throws CalFacadeException
-   */
-  public static DatePeriod getPeriod(String start, String end,
-                               int defaultField, int defaultVal,
-                               int maxField,
-                               int maxVal) throws CalFacadeException {
-    Locale loc = BwLocale.getLocale();
-    Calendar startCal = Calendar.getInstance(loc);
-    startCal.set(Calendar.HOUR_OF_DAY, 0);
-    startCal.set(Calendar.MINUTE, 0);
-    startCal.set(Calendar.SECOND, 0);
-
-    Calendar endCal = Calendar.getInstance(loc);
-    endCal.set(Calendar.HOUR_OF_DAY, 0);
-    endCal.set(Calendar.MINUTE, 0);
-    endCal.set(Calendar.SECOND, 0);
-
-    if (start != null) {
-      startCal.setTime(fromDate(start));
-    }
-
-    if (end == null) {
-      endCal.add(defaultField, defaultVal);
-    } else {
-      endCal.setTime(fromDate(end));
-    }
-
-    // Don't allow more than a month
-    Calendar check = Calendar.getInstance(loc);
-    check.setTime(startCal.getTime());
-    check.add(maxField, maxVal);
-
-    if (check.before(endCal)) {
-      return null;
-    }
-
-    DatePeriod dp = new DatePeriod();
-
-    dp.start = DateTimeUtil.getDateTime(isoDateTime(startCal.getTime()),
-                                        false,
-                                        false,
-                                        false,   // floating
-                                        null,   // tzid
-                                        null);  // tzowner
-    dp.end = DateTimeUtil.getDateTime(isoDateTime(endCal.getTime()),
-                                      false,
-                                      false,
-                                      false,   // floating
-                                      null,   // tzid
-                                      null);   // tzowner
-
-    return dp;
-  }
-
-  private static Date fromDate(String dt) throws CalFacadeException {
-    if (dt == null) {
-      return null;
-    }
-
-    if (dt.indexOf("T") > 0) {
-      return fromDateTime(dt);
-    }
-
-    if (dt.indexOf("-") < 0) {
-      return fromISODate(dt);
-    }
-
-    return fromRfcDate(dt);
-  }
-
-  private static Date fromDateTime(String dt) throws CalFacadeException {
-    if (dt == null) {
-      return null;
-    }
-
-    if (dt.indexOf("-") < 0) {
-      return fromISODateTimeUTC(dt);
-    }
-
-    return fromRfcDateTimeUTC(dt);
-  }
-}

Modified: trunk/calFacade/src/org/bedework/calfacade/util/xml/CalDavParseUtil.java
===================================================================
--- trunk/calFacade/src/org/bedework/calfacade/util/xml/CalDavParseUtil.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calFacade/src/org/bedework/calfacade/util/xml/CalDavParseUtil.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -29,7 +29,7 @@
 import org.bedework.calfacade.exc.CalFacadeBadRequest;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.BwDateTime;
-import org.bedework.calfacade.util.DateTimeUtil;
+import org.bedework.calfacade.util.BwDateTimeUtil;
 
 import net.fortuna.ical4j.model.TimeZone;
 
@@ -81,7 +81,7 @@
 
       if (nmAttr != null) {
         attrCt--;
-        start = DateTimeUtil.getDateTime(nmAttr.getNodeValue(),
+        start = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(),
                                          false,
                                          tz == null,   // utc
                                          false,
@@ -94,7 +94,7 @@
 
       if (nmAttr != null) {
         attrCt--;
-        end = DateTimeUtil.getDateTime(nmAttr.getNodeValue(),
+        end = BwDateTimeUtil.getDateTime(nmAttr.getNodeValue(),
                                        false,
                                        tz == null,   // utc
                                        false,

Modified: trunk/calsvc/src/org/bedework/calsvc/Calendars.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calsvc/src/org/bedework/calsvc/Calendars.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -33,10 +33,10 @@
 import org.bedework.calfacade.RecurringRetrievalMode.Rmode;
 import org.bedework.calfacade.base.BwShareableDbentity;
 import org.bedework.calfacade.exc.CalFacadeAccessException;
+import org.bedework.calfacade.exc.CalFacadeBadDateException;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.svc.EventInfo;
 import org.bedework.calfacade.svc.prefs.BwPreferences;
-import org.bedework.calfacade.util.DateTimeUtil;
 import org.bedework.calsvci.CalendarsI;
 import org.bedework.calsvci.EventsI.UpdateResult;
 import org.bedework.http.client.dav.DavClient;
@@ -44,6 +44,8 @@
 import org.bedework.icalendar.Icalendar;
 
 import edu.rpi.cmt.access.PrivilegeDefs;
+import edu.rpi.sss.util.DateTimeUtil;
+import edu.rpi.sss.util.DateTimeUtil.BadDateException;
 
 import net.fortuna.ical4j.model.Calendar;
 
@@ -378,31 +380,35 @@
   }
 
   public void checkRefresh(BwCalendar val) throws CalFacadeException {
-    if (val == null) {
-      return;
-    }
+    try {
+      if (val == null) {
+        return;
+      }
 
-    if (val.getExternalSub()) {
-      /* This is a subscription to an external calendar.
-       */
+      if (val.getExternalSub()) {
+        /* This is a subscription to an external calendar.
+         */
 
-      if (val.getLastRefresh() == null) {
-        refreshCalendar(val);
-      } else {
-        long nextRefresh = DateTimeUtil.fromISODateTime(val.getLastRefresh()).getTime() +
-                 (val.getRefreshRate() * 1000);
-        long curTime = System.currentTimeMillis();
-        if (nextRefresh < curTime) {
+        if (val.getLastRefresh() == null) {
           refreshCalendar(val);
+        } else {
+          long nextRefresh = DateTimeUtil.fromISODateTime(val.getLastRefresh()).getTime() +
+                   (val.getRefreshRate() * 1000);
+          long curTime = System.currentTimeMillis();
+          if (nextRefresh < curTime) {
+            refreshCalendar(val);
+          }
         }
+        return;
       }
-      return;
-    }
 
-    if (val.getCollectionInfo().childrenAllowed) {
-      for (BwCalendar c: getChildren(val)) {
-        checkRefresh(c);
+      if (val.getCollectionInfo().childrenAllowed) {
+        for (BwCalendar c: getChildren(val)) {
+          checkRefresh(c);
+        }
       }
+    } catch (BadDateException bde) {
+      throw new CalFacadeBadDateException();
     }
   }
 
@@ -426,10 +432,10 @@
    * @throws CalFacadeException
    */
   private void refreshCalendar(BwCalendar val) throws CalFacadeException {
-    // Mark as refreshed to stop calls back here
-    val.setLastRefresh(DateTimeUtil.isoDateTime(new Date(System.currentTimeMillis())));
+    try {
+      // Mark as refreshed to stop calls back here
+      val.setLastRefresh(DateTimeUtil.isoDateTime(new Date(System.currentTimeMillis())));
 
-    try {
       DavClient cl = new DavClient(val.getAliasUri(),
                                    15 * 1000,    // 15 seconds timeout
                                    debug);

Modified: trunk/calsvc/src/org/bedework/calsvc/Indexing.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/Indexing.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calsvc/src/org/bedework/calsvc/Indexing.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -32,7 +32,6 @@
 import org.bedework.calfacade.base.BwOwnedDbentity;
 import org.bedework.calfacade.exc.CalFacadeException;
 import org.bedework.calfacade.svc.EventInfo;
-import org.bedework.calfacade.util.DateTimeUtil;
 import org.bedework.calsvc.indexing.BwIndexKey;
 import org.bedework.calsvc.indexing.BwIndexer;
 import org.bedework.calsvc.indexing.BwIndexerFactory;
@@ -42,6 +41,7 @@
 import edu.rpi.cct.misc.indexing.Index;
 import edu.rpi.cct.misc.indexing.IndexException;
 import edu.rpi.cct.misc.indexing.SearchLimits;
+import edu.rpi.sss.util.DateTimeUtil;
 
 import java.util.ArrayList;
 import java.util.Collection;

Modified: trunk/calsvc/src/org/bedework/calsvc/TimeZonesStoreImpl.java
===================================================================
--- trunk/calsvc/src/org/bedework/calsvc/TimeZonesStoreImpl.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/calsvc/src/org/bedework/calsvc/TimeZonesStoreImpl.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -38,7 +38,7 @@
 import org.bedework.calfacade.base.UpdateFromTimeZonesInfo.UnknownTimezoneInfo;
 import org.bedework.calfacade.exc.CalFacadeAccessException;
 import org.bedework.calfacade.exc.CalFacadeException;
-import org.bedework.calfacade.util.DateTimeUtil;
+import org.bedework.calfacade.util.BwDateTimeUtil;
 import org.bedework.calsvci.TimeZonesStoreI;
 import org.bedework.icalendar.IcalTranslator;
 
@@ -470,7 +470,7 @@
     }
 
     try {
-      BwDateTime newVal = DateTimeUtil.getDateTime(val.getDtval(), false, false,
+      BwDateTime newVal = BwDateTimeUtil.getDateTime(val.getDtval(), false, false,
                                                    false, val.getTzid(),
                                                    val.getTzowner());
 

Modified: trunk/mail/src/org/bedework/mail/MailUtil.java
===================================================================
--- trunk/mail/src/org/bedework/mail/MailUtil.java	2008-11-14 15:31:34 UTC (rev 743)
+++ trunk/mail/src/org/bedework/mail/MailUtil.java	2008-11-20 20:11:58 UTC (rev 744)
@@ -59,7 +59,7 @@
 import org.bedework.calfacade.mail.MailerIntf;
 import org.bedework.calfacade.mail.Message;
 import org.bedework.calfacade.mail.ObjectAttachment;
-import org.bedework.calfacade.util.DateTimeUtil;
+import org.bedework.calfacade.util.BwDateTimeUtil;
 
 
 import java.text.DateFormat;
@@ -113,7 +113,7 @@
   public static String formatDate(BwDateTime dt) {
     DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
     try {
-      return df.format(DateTimeUtil.getDate(dt));
+      return df.format(BwDateTimeUtil.getDate(dt));
     } catch (Throwable t) {
       return t.getMessage();
     }



More information about the Bedework-commit mailing list