/** * Updates the timezone associated with the property's value. If the specified timezone is equivalent to UTC any * existing TZID parameters will be removed. Note that this method is only applicable where the current date is an * instance of <code>DateTime</code>. For all other cases an <code>UnsupportedOperationException</code> will be * thrown. * * @param timezone */ private void updateTimeZone(final TimeZone timezone) { this.timeZone = timezone; if (timezone != null) { if (getDate() != null && !(getDate() instanceof DateTime)) { throw new UnsupportedOperationException( "TimeZone is not applicable to current value"); } if (getDate() != null) { ((DateTime) getDate()).setTimeZone(timezone); } getParameters().replace(new TzId(timezone.getID())); } else { // use setUtc() to reset timezone.. setUtc(isUtc()); } }
static void correctTzParameterFrom(DateProperty property) { if (property.getValue() != null && property.getValue().endsWith("Z")) { property.getParameters().removeAll(Parameter.TZID); return; } if (property.getParameter(Parameter.TZID) != null) { String newTimezone = getCorrectedTimezoneFromTzParameter(property); String value = property.getValue(); correctTzParameter(property, newTimezone); if (newTimezone != null) { property.setTimeZone(TIMEZONE_REGISTRY.getTimeZone(newTimezone)); try { property.setValue(value); } catch (ParseException e) { LOG.warn("Failed to reset property value", e); } } else { property.setUtc(true); } } }
/** * Creates a new instance of the named property with an initial timezone. * * @param name property name * @param timezone initial timezone */ public DateProperty(final String name, TimeZone timezone, PropertyFactory factory) { super(name, factory); updateTimeZone(timezone); }
/** * Resets the VTIMEZONE associated with the property. If utc is true, any TZID parameters are removed and the Java * timezone is updated to UTC time. If utc is false, TZID parameters are removed and the Java timezone is set to the * default timezone (i.e. represents a "floating" local time) * @param utc a UTC value */ public final void setUtc(final boolean utc) { if (getDate() != null && (getDate() instanceof DateTime)) { ((DateTime) getDate()).setUtc(utc); } getParameters().remove(getParameter(Parameter.TZID)); }
@Override public void applyTo(DateProperty element) { TzHelper.correctTzParameterFrom(element); if (!element.isUtc() || element.getParameter(Parameter.TZID) == null) { return; } element.getParameters().removeAll(Parameter.TZID); element.setUtc(true); }
private net.fortuna.ical4j.model.Date getDateValue(DateProperty prop) { if (prop == null) { return null; } return prop.getDate(); }
/** * Sets the date value of this property. The timezone and value of this * instance will also be updated accordingly. * * @param date The date to set. */ public final void setDate(final Date date) { this.date = date; if (date instanceof DateTime) { if (Value.DATE.equals(getParameter(Parameter.VALUE))) { getParameters().replace(Value.DATE_TIME); } updateTimeZone(((DateTime) date).getTimeZone()); } else { if (date != null) { getParameters().replace(Value.DATE); } /* else { getParameters().removeAll(Parameter.VALUE); } */ // ensure timezone is null for VALUE=DATE or null properties.. updateTimeZone(null); } }
private void copyDateProperty(ContentValues c, String dbName, String dbTzName, DateProperty date) { if (dbName != null && date.getDate() != null) { c.put(dbName, date.getDate().getTime()); // ms since epoc in GMT if (dbTzName != null) { if (date.isUtc() || date.getTimeZone() == null) c.put(dbTzName, "UTC"); else c.put(dbTzName, date.getTimeZone().getID()); } } }
private void updateTimeZone(final Property property, final TimeZone timezone) { try { ((DateProperty) property).setTimeZone(timezone); } catch (final ClassCastException e) { try { ((DateListProperty) property).setTimeZone(timezone); } catch (final ClassCastException e2) { if (CompatibilityHints.isHintEnabled( CompatibilityHints.KEY_RELAXED_PARSING)) { // log.warn("Error setting timezone [" + timezone.getID() // + "] on property [" + property.getName() // + "]", e); // } } else { throw e2; } } } } }
private void initDateProp(final DateProperty dt, final TimeZoneRegistry tzreg) throws CalFacadeException { try { String tzid = getTzid(); ParameterList pl = dt.getParameters(); if (getDateType()) { pl.add(Value.DATE); } if (tzid != null) { dt.setTimeZone(tzreg.getTimeZone(tzid)); } dt.setValue(getDtval()); } catch (Throwable t) { throw new CalFacadeException(t); } }
/** * Default setValue() implementation. Allows for either DATE or DATE-TIME values. * * @param value a string representation of a DATE or DATE-TIME value * @throws ParseException where the specified value is not a valid DATE or DATE-TIME * representation */ public void setValue(final String value) throws ParseException { // value can be either a date-time or a date.. if (Value.DATE.equals(getParameter(Parameter.VALUE))) { // ensure timezone is null for VALUE=DATE properties.. updateTimeZone(null); this.date = new Date(value); } else if (value != null && !value.isEmpty()){ this.date = new DateTime(value, timeZone); } }
/** * @param comp The component. */ private void componentToUTC(Component comp) { // Do to each top-level property for (Property prop : (List<Property>) comp.getProperties()) { if (prop instanceof DateProperty) { DateProperty dprop = (DateProperty) prop; Date date = dprop.getDate(); if (date instanceof DateTime && (((DateTime) date).getTimeZone() != null)) { dprop.setUtc(true); } } } // Do to each embedded component ComponentList<? extends CalendarComponent> subcomps = null; if (comp instanceof VEvent) { subcomps = ((VEvent) comp).getAlarms() ; } else if (comp instanceof VToDo) { subcomps = ((VToDo)comp).getAlarms(); } if (subcomps != null) { for (CalendarComponent subcomp : subcomps) { componentToUTC(subcomp); } } }
final Dur dur) throws CalFacadeException { DtEnd dtEnd; java.util.Date endDt = dur.getTime(dtStart.getDate()); DateTime d = new DateTime(endDt); if (tzid != null) { DateTime sd = (DateTime)dtStart.getDate(); if (tzid != null) { addIcalParameter(dtEnd, tzid); } else if (dtStart.isUtc()) { dtEnd.setUtc(true);
/** * {@inheritDoc} */ public final void validate() throws ValidationException { super.validate(); /* * ; the following are optional, ; but MUST NOT occur more than once (";" "VALUE" "=" ("DATE-TIME" / "DATE")) / * (";" tzidparam) / */ /* * ; the following is optional, ; and MAY occur more than once (";" xparam) */ } }
private void createDateProperty(Property property, Resource r_event, String rdfProperty) throws RDFParseException, RDFHandlerException { if(property != null) { if(property instanceof DateProperty) { DateProperty dateProperty = (DateProperty)property; URI p_dateprop = createURI(rdfProperty); Literal v_dateprop = valueFactory.createLiteral(getXMLCalendar(dateProperty.getDate(),dateProperty.getTimeZone())); rdfHandler.handleStatement(createStatement(r_event,p_dateprop,v_dateprop)); } else if(property instanceof DateListProperty) { DateListProperty dateProperty = (DateListProperty)property; URI p_dateprop = createURI(rdfProperty); for (Date date : (Iterable<Date>) dateProperty.getDates()) { Literal v_dateprop = valueFactory.createLiteral(getXMLCalendar(date, dateProperty.getTimeZone())); rdfHandler.handleStatement(createStatement(r_event, p_dateprop, v_dateprop)); } } } }
protected void setDatePropertyValue(DateProperty prop, Date date) { if (prop == null) { return; } Value value = (Value) prop.getParameters().getParameter(Parameter.VALUE); if (value != null) { prop.getParameters().remove(value); } // Add VALUE=DATE for Date values, otherwise // leave out VALUE=DATE-TIME because it is redundant if(! (date instanceof DateTime)) { prop.getParameters().add(Value.DATE); } }
if (Value.DATE.equals(dp.getParameter(Parameter.VALUE))) { return DataType.DATE;
/** Make date time based on ical property * * @param val * @return BwDateTime * @throws CalFacadeException */ public static BwDateTime makeBwDateTime(final DateProperty val) throws CalFacadeException { Parameter par = getIcalParameter(val, "VALUE"); BwDateTime bwdt = makeBwDateTime((par != null) && (par.equals(Value.DATE)), val.getValue(), getTzid(val)); par = getIcalParameter(val, "RANGE"); if (par != null) { /* XXX What do I do with it? */ bwdt.range = par.getValue(); } return bwdt; }