Java Code Examples for net.fortuna.ical4j.model.DateTime#toString()
The following examples show how to use
net.fortuna.ical4j.model.DateTime#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ICalendarUtils.java From cosmo with Apache License 2.0 | 6 votes |
/** * Return a DateTime instance that is normalized according to the * offset of the specified timezone as compared to the default * system timezone. * * @param utcDateTime point in time * @param tz timezone The timezone. * @return The date. */ public static Date normalizeUTCDateTimeToDefaultOffset(DateTime utcDateTime, TimeZone tz) { if(!utcDateTime.isUtc()) { throw new IllegalArgumentException("datetime must be utc"); } // if no timezone nothing to do if (tz == null) { return utcDateTime; } // create copy, and set timezone DateTime copy = (DateTime) Dates.getInstance(utcDateTime, utcDateTime); copy.setTimeZone(tz); // Create floating instance of local time, which will give // us the correct offset try { return new DateTime(copy.toString()); } catch (ParseException e) { throw new CosmoParseException("error creating Date instance", e); } }
Example 2
Source File: EventStampInterceptor.java From cosmo with Apache License 2.0 | 6 votes |
private String fromDateToStringNoTimezone(Date date) { if(date==null) { return null; } if(date instanceof DateTime) { DateTime dt = (DateTime) date; // If DateTime has a timezone, then convert to UTC before // serializing as String. if(dt.getTimeZone()!=null) { // clone instance first to prevent changes to original instance DateTime copy = new DateTime(dt); copy.setUtc(true); return copy.toString(); } else { return dt.toString(); } } else { return date.toString(); } }
Example 3
Source File: ModificationUidImpl.java From cosmo with Apache License 2.0 | 6 votes |
/** * Converts an ical4j Date instance to a string representation. If the instance * is a DateTime and has a timezone, then the string representation will be * UTC. * @param date date to format * @return string representation of date */ public static String fromDateToStringNoTimezone(Date date) { if(date==null) { return null; } if(date instanceof DateTime) { DateTime dt = (DateTime) date; // If DateTime has a timezone, then convert to UTC before // serializing as String. if(dt.getTimeZone()!=null) { // clone instance first to prevent changes to original instance DateTime copy = new DateTime(dt); copy.setUtc(true); return copy.toString(); } else { return dt.toString(); } } else { return date.toString(); } }
Example 4
Source File: EventResource.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * @param recurIdList * @param iterator The Data in Iterator should be DateTime */ public void fillRecurIDListbyDateTime(ArrayList<String> recurIdList, DateList recurDates) { String sDateTime; Iterator iterator = recurDates.iterator(); while (iterator.hasNext()) { DateTime dateTime = (DateTime)iterator.next(); dateTime.setUtc(true); sDateTime = dateTime.toString(); recurIdList.add(sDateTime); } }
Example 5
Source File: EventResource.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * @param recurIdList * @param iterator The Data in Iterator should be DateTime */ public void fillRecurIDListbyDate(ArrayList<String> recurIdList, DateList recurDates) { String sDateTime; Iterator iterator = recurDates.iterator(); while (iterator.hasNext()) { DateTime dateTime = (DateTime)iterator.next(); sDateTime = dateTime.toString(); int positionT = sDateTime.indexOf("T"); if(positionT>0){ sDateTime = sDateTime.substring(0, positionT); } recurIdList.add(sDateTime); } }
Example 6
Source File: EventResource.java From XPagesExtensionLibrary with Apache License 2.0 | 5 votes |
/** * @param recurIdList * @param iterator The Data in Iterator should be DateTime */ public void removeRecurIDListbyDateTime(ArrayList<String> recurIdList, DateList exDates) { String sDateTime; Iterator iterator = exDates.iterator(); while (iterator.hasNext()) { DateTime exDate = (DateTime)iterator.next(); exDate.setUtc(true); // exDates must have same type with value sDateTime = exDate.toString(); recurIdList.remove(sDateTime); } }
Example 7
Source File: InstanceList.java From cosmo with Apache License 2.0 | 4 votes |
/** * Adjust a floating time if a timezone is present. A floating time * is initially created with the default system timezone. If a timezone * if present, we need to adjust the floating time to be in specified * timezone. This allows a server in the US to return floating times for * a query made by someone whos timezone is in Australia. If no timezone is * set for the InstanceList, then the system default timezone will be * used in floating time calculations. * <p/> * What happens is a floating time will get converted into a * date/time with a timezone. This is ok for comparison and recurrence * generation purposes. Note that Instances will get indexed as a UTC * date/time and for floating DateTimes, the the recurrenceId associated * with the Instance loses its "floating" property. * * @param date The date. * @return The date. */ private Date adjustFloatingDateIfNecessary(Date date) { if (timezone == null || !(date instanceof DateTime)) { return date; } DateTime dtDate = (DateTime) date; if (dtDate.isUtc() || dtDate.getTimeZone() != null) { return date; } try { return new DateTime(dtDate.toString(), timezone); } catch (ParseException e) { throw new CosmoParseException("error parsing date", e); } }