diff --git a/src/main/java/net/fortuna/ical4j/model/property/DateListProperty.java b/src/main/java/net/fortuna/ical4j/model/property/DateListProperty.java
index 5f1d1ab25..bfce7ef61 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/DateListProperty.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/DateListProperty.java
@@ -32,13 +32,13 @@
package net.fortuna.ical4j.model.property;
import net.fortuna.ical4j.model.*;
-import net.fortuna.ical4j.model.parameter.TzId;
-import net.fortuna.ical4j.model.parameter.Value;
import net.fortuna.ical4j.util.Strings;
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
+import java.time.temporal.Temporal;
+import java.util.Optional;
/**
* $Id$
@@ -47,16 +47,27 @@
*
* Base class for properties with a list of dates as a value.
*
+ * Note that generics have been introduced as part of the migration to the new Java Date/Time API.
+ * Date properties should now indicate the applicable {@link Temporal} type for the property.
+ *
+ * For example:
+ *
+ *
+ * - UTC-based properties should use {@link java.time.Instant} to represent UTC time
+ * - Date-only properties should use {@link java.time.LocalDate} to represent a date value
+ * - Date-time properties should use {@link java.time.ZonedDateTime} to represent a date-time value influenced by timezone rules
+ *
+ *
* @author Ben Fortuna
*/
-public abstract class DateListProperty extends Property {
+public abstract class DateListProperty extends Property {
/**
*
*/
private static final long serialVersionUID = 5233773091972759919L;
- private DateList dates;
+ private DateList dates;
private TimeZone timeZone;
@@ -64,7 +75,7 @@ public abstract class DateListProperty extends Property {
* @param name the property name
*/
public DateListProperty(final String name, PropertyFactory factory) {
- this(name, new DateList(Value.DATE_TIME), factory);
+ this(name, new DateList<>(), factory);
}
/**
@@ -79,7 +90,7 @@ public DateListProperty(final String name, final ParameterList parameters, Prope
* @param name the property name
* @param dates a list of initial dates for the property
*/
- public DateListProperty(final String name, final DateList dates, PropertyFactory factory) {
+ public DateListProperty(final String name, final DateList dates, PropertyFactory factory) {
this(name, new ParameterList(), dates, factory);
}
@@ -88,19 +99,16 @@ public DateListProperty(final String name, final DateList dates, PropertyFactory
* @param parameters property parameters
* @param dates a list of initial dates for the property
*/
- public DateListProperty(final String name, final ParameterList parameters, final DateList dates,
+ public DateListProperty(final String name, final ParameterList parameters, final DateList dates,
PropertyFactory factory) {
super(name, parameters, factory);
this.dates = dates;
- if (dates != null && !Value.DATE_TIME.equals(dates.getType())) {
- getParameters().replace(dates.getType());
- }
}
/**
* @return Returns the dates.
*/
- public final DateList getDates() {
+ public final DateList getDates() {
return dates;
}
@@ -108,8 +116,7 @@ public final DateList getDates() {
* {@inheritDoc}
*/
public void setValue(final String aValue) throws ParseException {
- dates = new DateList(aValue, getParameter(Parameter.VALUE),
- timeZone);
+ dates = DateList.parse(aValue);
}
/**
@@ -131,13 +138,7 @@ public void setTimeZone(final TimeZone timezone) {
}
this.timeZone = timezone;
if (timezone != null) {
- if (!Value.DATE_TIME.equals(getDates().getType())) {
- throw new UnsupportedOperationException(
- "TimeZone is not applicable to current value");
- }
- dates.setTimeZone(timezone);
- getParameters().remove(getParameter(Parameter.TZID));
- final TzId tzId = new TzId(timezone.getID());
+ final net.fortuna.ical4j.model.parameter.TzId tzId = new net.fortuna.ical4j.model.parameter.TzId(timezone.getID());
getParameters().replace(tzId);
} else {
// use setUtc() to reset timezone..
@@ -148,8 +149,8 @@ public void setTimeZone(final TimeZone timezone) {
/**
* @return the timezone
*/
- public final TimeZone getTimeZone() {
- return timeZone;
+ public final Optional getTimeZone() {
+ return Optional.ofNullable(timeZone);
}
/**
@@ -160,12 +161,12 @@ public final TimeZone getTimeZone() {
* @param utc the UTC value
*/
public final void setUtc(final boolean utc) {
- if (dates == null || !Value.DATE_TIME.equals(dates.getType())) {
- throw new UnsupportedOperationException(
- "TimeZone is not applicable to current value");
+ if (dates == null) {
+ throw new UnsupportedOperationException("TimeZone is not applicable to current value");
+ }
+ if (utc) {
+ getParameters().remove(getParameter(Parameter.TZID));
}
- dates.setUtc(utc);
- getParameters().remove(getParameter(Parameter.TZID));
}
/**
diff --git a/src/main/java/net/fortuna/ical4j/model/property/DtEnd.java b/src/main/java/net/fortuna/ical4j/model/property/DtEnd.java
index a8c7de6b3..a876f44d9 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/DtEnd.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/DtEnd.java
@@ -107,7 +107,7 @@
*
* @author Ben Fortuna
*/
-public class DtEnd extends DateProperty {
+public class DtEnd extends DateProperty {
private static final long serialVersionUID = 8107416684717228297L;
@@ -167,7 +167,7 @@ public DtEnd(final ParameterList aList, final String aValue)
*
* @param aDate a date
*/
- public DtEnd(final Temporal aDate) {
+ public DtEnd(final T aDate) {
super(DTEND, new Factory());
setDate(aDate);
}
@@ -178,7 +178,7 @@ public DtEnd(final Temporal aDate) {
* @param time the time of the DtEnd
* @param utc specifies whether time is UTC
*/
- public DtEnd(final Temporal time, final boolean utc) {
+ public DtEnd(final T time, final boolean utc) {
super(DTEND, new Factory());
setDate(time);
setUtc(utc);
@@ -190,7 +190,7 @@ public DtEnd(final Temporal time, final boolean utc) {
* @param aList a list of parameters for this component
* @param aDate a date
*/
- public DtEnd(final ParameterList aList, final Temporal aDate) {
+ public DtEnd(final ParameterList aList, final T aDate) {
super(DTEND, aList, new Factory());
setDate(aDate);
}
@@ -208,7 +208,7 @@ public Property createProperty(final ParameterList parameters, final String valu
}
public Property createProperty() {
- return new DtEnd();
+ return new DtEnd<>();
}
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/DtStart.java b/src/main/java/net/fortuna/ical4j/model/property/DtStart.java
index d3d5b6e73..722ed6247 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/DtStart.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/DtStart.java
@@ -105,7 +105,7 @@
*
* @author Ben Fortuna
*/
-public class DtStart extends DateProperty {
+public class DtStart extends DateProperty {
private static final long serialVersionUID = -5707097476081111815L;
@@ -127,9 +127,9 @@ public DtStart(TimeZone timezone) {
/**
* @param aValue a value string for this component
- * @throws ParseException where the specified value string is not a valid date-time/date representation
+ * @throws java.time.format.DateTimeParseException where the specified value string is not a valid date-time/date representation
*/
- public DtStart(final String aValue) throws ParseException {
+ public DtStart(final String aValue) {
super(DTSTART, new Factory());
setValue(aValue);
}
@@ -139,10 +139,10 @@ public DtStart(final String aValue) throws ParseException {
*
* @param value a string representation of a DTSTART value
* @param timezone initial timezone
- * @throws ParseException where the specified value is not a valid string
+ * @throws java.time.format.DateTimeParseException where the specified value is not a valid string
* representation
*/
- public DtStart(String value, TimeZone timezone) throws ParseException {
+ public DtStart(String value, TimeZone timezone) {
super(DTSTART, timezone, new Factory());
setValue(value);
}
@@ -150,10 +150,9 @@ public DtStart(String value, TimeZone timezone) throws ParseException {
/**
* @param aList a list of parameters for this component
* @param aValue a value string for this component
- * @throws ParseException where the specified value string is not a valid date-time/date representation
+ * @throws java.time.format.DateTimeParseException where the specified value string is not a valid date-time/date representation
*/
- public DtStart(final ParameterList aList, final String aValue)
- throws ParseException {
+ public DtStart(final ParameterList aList, final String aValue) {
super(DTSTART, aList, new Factory());
setValue(aValue);
}
@@ -163,7 +162,7 @@ public DtStart(final ParameterList aList, final String aValue)
*
* @param aDate a date
*/
- public DtStart(final Temporal aDate) {
+ public DtStart(final T aDate) {
super(DTSTART, new Factory());
setDate(aDate);
}
@@ -174,7 +173,7 @@ public DtStart(final Temporal aDate) {
* @param time the time of the DtStart
* @param utc specifies whether time is UTC
*/
- public DtStart(final Temporal time, final boolean utc) {
+ public DtStart(final T time, final boolean utc) {
super(DTSTART, new Factory());
setDate(time);
setUtc(utc);
@@ -186,7 +185,7 @@ public DtStart(final Temporal time, final boolean utc) {
* @param aList a list of parameters for this component
* @param aDate a date
*/
- public DtStart(final ParameterList aList, final Temporal aDate) {
+ public DtStart(final ParameterList aList, final T aDate) {
super(DTSTART, aList, new Factory());
setDate(aDate);
}
@@ -204,7 +203,7 @@ public Property createProperty(final ParameterList parameters, final String valu
}
public Property createProperty() {
- return new DtStart();
+ return new DtStart<>();
}
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/Due.java b/src/main/java/net/fortuna/ical4j/model/property/Due.java
index e08919251..e789dad1b 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/Due.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/Due.java
@@ -93,19 +93,10 @@
*
* @author Ben Fortuna
*/
-public class Due extends DateProperty {
+public class Due extends DateProperty {
private static final long serialVersionUID = -2965312347832730406L;
- /**
- * Default constructor. The time value is initialised to the time of instantiation.
- */
- public Due() {
- super(DUE, new Factory());
- // defaults to UTC time..
- setDate(LocalDateTime.now(ZoneOffset.UTC));
- }
-
/**
* Creates a new DUE property initialised with the specified timezone.
*
@@ -119,9 +110,9 @@ public Due(TimeZone timezone) {
* Creates a new instance initialised with the parsed value.
*
* @param value the DUE value string to parse
- * @throws ParseException where the specified string is not a valid DUE value representation
+ * @throws java.time.format.DateTimeParseException where the specified string is not a valid DUE value representation
*/
- public Due(final String value) throws ParseException {
+ public Due(final String value) {
super(DUE, new Factory());
setValue(value);
}
@@ -131,10 +122,10 @@ public Due(final String value) throws ParseException {
*
* @param value a string representation of a DUE value
* @param timezone initial timezone
- * @throws ParseException where the specified value is not a valid string
+ * @throws java.time.format.DateTimeParseException where the specified value is not a valid string
* representation
*/
- public Due(String value, TimeZone timezone) throws ParseException {
+ public Due(String value, TimeZone timezone) {
super(DUE, timezone, new Factory());
setValue(value);
}
@@ -142,10 +133,9 @@ public Due(String value, TimeZone timezone) throws ParseException {
/**
* @param aList a list of parameters for this component
* @param aValue a value string for this component
- * @throws ParseException when the specified string is not a valid date/date-time representation
+ * @throws java.time.format.DateTimeParseException when the specified string is not a valid date/date-time representation
*/
- public Due(final ParameterList aList, final String aValue)
- throws ParseException {
+ public Due(final ParameterList aList, final String aValue) {
super(DUE, aList, new Factory());
setValue(aValue);
}
@@ -155,7 +145,7 @@ public Due(final ParameterList aList, final String aValue)
*
* @param aDate a date
*/
- public Due(final Temporal aDate) {
+ public Due(final T aDate) {
super(DUE, new Factory());
setDate(aDate);
}
@@ -166,7 +156,7 @@ public Due(final Temporal aDate) {
* @param aList a list of parameters for this component
* @param aDate a date
*/
- public Due(final ParameterList aList, final Temporal aDate) {
+ public Due(final ParameterList aList, final T aDate) {
super(DUE, aList, new Factory());
setDate(aDate);
}
@@ -184,7 +174,7 @@ public Property createProperty(final ParameterList parameters, final String valu
}
public Property createProperty() {
- return new Due();
+ return new Due<>(LocalDateTime.now(ZoneOffset.UTC));
}
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/ExDate.java b/src/main/java/net/fortuna/ical4j/model/property/ExDate.java
index 11bfbb36a..7b96c1e57 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/ExDate.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/ExDate.java
@@ -39,6 +39,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
+import java.time.temporal.Temporal;
/**
* $Id$
@@ -49,7 +50,7 @@
*
* @author benf
*/
-public class ExDate extends DateListProperty {
+public class ExDate extends DateListProperty {
private static final long serialVersionUID = 2635730172243974463L;
@@ -74,7 +75,7 @@ public ExDate(final ParameterList aList, final String aValue)
/**
* @param dList a list of dates
*/
- public ExDate(final DateList dList) {
+ public ExDate(final DateList dList) {
super(EXDATE, dList, new Factory());
}
@@ -82,7 +83,7 @@ public ExDate(final DateList dList) {
* @param aList a list of parameters for this component
* @param dList a list of dates
*/
- public ExDate(final ParameterList aList, final DateList dList) {
+ public ExDate(final ParameterList aList, final DateList dList) {
super(EXDATE, aList, dList, new Factory());
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/RDate.java b/src/main/java/net/fortuna/ical4j/model/property/RDate.java
index 466384f4f..d8db63bba 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/RDate.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/RDate.java
@@ -40,6 +40,9 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
+import java.time.temporal.Temporal;
+import java.util.ArrayList;
+import java.util.List;
/**
* $Id$
@@ -127,18 +130,18 @@
*
* @author Ben Fortuna
*/
-public class RDate extends DateListProperty {
+public class RDate extends DateListProperty {
private static final long serialVersionUID = -3320381650013860193L;
- private PeriodList periods;
+ private PeriodList periods;
/**
* Default constructor.
*/
public RDate() {
super(RDATE, new Factory());
- periods = new PeriodList(false, true);
+ periods = null;
}
/**
@@ -149,7 +152,7 @@ public RDate() {
public RDate(final ParameterList aList, final String aValue)
throws ParseException {
super(RDATE, aList, new Factory());
- periods = new PeriodList(false, true);
+ periods = null;
setValue(aValue);
}
@@ -158,9 +161,9 @@ public RDate(final ParameterList aList, final String aValue)
*
* @param dates a list of dates
*/
- public RDate(final DateList dates) {
+ public RDate(final DateList dates) {
super(RDATE, dates, new Factory());
- periods = new PeriodList(false, true);
+ periods = null;
}
/**
@@ -169,9 +172,9 @@ public RDate(final DateList dates) {
* @param aList a list of parameters for this component
* @param dates a list of dates
*/
- public RDate(final ParameterList aList, final DateList dates) {
+ public RDate(final ParameterList aList, final DateList dates) {
super(RDATE, aList, dates, new Factory());
- periods = new PeriodList(false, true);
+ periods = null;
}
/**
@@ -179,9 +182,9 @@ public RDate(final ParameterList aList, final DateList dates) {
*
* @param periods a list of periods
*/
- public RDate(final PeriodList periods) {
- super(RDATE, new DateList(true), new Factory());
- this.periods = periods;
+ public RDate(final List> periods) {
+ super(RDATE, new DateList<>(true), new Factory());
+ this.periods = new PeriodList<>(periods);
}
/**
@@ -190,9 +193,9 @@ public RDate(final PeriodList periods) {
* @param aList a list of parameters for this component
* @param periods a list of periods
*/
- public RDate(final ParameterList aList, final PeriodList periods) {
- super(RDATE, aList, new DateList(true), new Factory());
- this.periods = periods;
+ public RDate(final ParameterList aList, final List> periods) {
+ super(RDATE, aList, new DateList<>(true), new Factory());
+ this.periods = new PeriodList<>(periods);
}
/**
@@ -227,8 +230,8 @@ public final void validate() throws ValidationException {
/**
* @return Returns the period list.
*/
- public final PeriodList getPeriods() {
- return periods;
+ public final List> getPeriods() {
+ return new ArrayList<>(periods.getPeriods());
}
/**
@@ -236,7 +239,7 @@ public final PeriodList getPeriods() {
*/
public final void setValue(final String aValue) throws ParseException {
if (Value.PERIOD.equals(getParameter(Parameter.VALUE))) {
- periods = new PeriodList(aValue);
+ periods = PeriodList.parse(aValue);
} else {
super.setValue(aValue);
}
@@ -246,23 +249,12 @@ public final void setValue(final String aValue) throws ParseException {
* {@inheritDoc}
*/
public final String getValue() {
- if (periods != null && !(periods.isEmpty() && periods.isUnmodifiable())) {
- return Strings.valueOf(getPeriods());
+ if (periods != null) {
+ return Strings.valueOf(periods);
}
return super.getValue();
}
- /**
- * {@inheritDoc}
- */
- public final void setTimeZone(TimeZone timezone) {
- if (periods != null && !(periods.isEmpty() && periods.isUnmodifiable())) {
- periods.setTimeZone(timezone);
- } else {
- super.setTimeZone(timezone);
- }
- }
-
public static class Factory extends Content.Factory implements PropertyFactory {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/net/fortuna/ical4j/model/property/RecurrenceId.java b/src/main/java/net/fortuna/ical4j/model/property/RecurrenceId.java
index c9f497fe7..d69171945 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/RecurrenceId.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/RecurrenceId.java
@@ -128,18 +128,10 @@
*
* @author Ben Fortuna
*/
-public class RecurrenceId extends DateProperty {
+public class RecurrenceId extends DateProperty {
private static final long serialVersionUID = 4456883817126011006L;
- /**
- * Default constructor.
- */
- public RecurrenceId() {
- super(RECURRENCE_ID, new Factory());
- setDate(LocalDateTime.now(ZoneOffset.UTC));
- }
-
/**
* Creates a new RECURRENCE_ID property initialised with the specified timezone.
*
@@ -189,7 +181,7 @@ public RecurrenceId(final ParameterList aList, final String aValue)
*
* @param aDate a date representation of a date or date-time
*/
- public RecurrenceId(final Temporal aDate) {
+ public RecurrenceId(final T aDate) {
super(RECURRENCE_ID, new Factory());
setDate(aDate);
}
@@ -200,7 +192,7 @@ public RecurrenceId(final Temporal aDate) {
* @param aList a list of parameters for this component
* @param aDate a date representation of a date or date-time
*/
- public RecurrenceId(final ParameterList aList, final Temporal aDate) {
+ public RecurrenceId(final ParameterList aList, final T aDate) {
super(RECURRENCE_ID, aList, new Factory());
setDate(aDate);
}
@@ -237,7 +229,7 @@ public Property createProperty(final ParameterList parameters, final String valu
}
public Property createProperty() {
- return new RecurrenceId();
+ return new RecurrenceId<>(LocalDateTime.now(ZoneOffset.UTC));
}
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/Trigger.java b/src/main/java/net/fortuna/ical4j/model/property/Trigger.java
index db6d47e42..501298b28 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/Trigger.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/Trigger.java
@@ -36,10 +36,8 @@
import net.fortuna.ical4j.validate.ParameterValidator;
import net.fortuna.ical4j.validate.ValidationException;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.text.ParseException;
import java.time.Instant;
+import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAmount;
/**
@@ -171,15 +169,19 @@ public Trigger(final ParameterList aList, final String aValue) {
*/
@Deprecated
public Trigger(final Dur duration) {
- this(TemporalAmountAdapter.from(duration).getDuration());
+ this(TemporalAmountAdapter.from(duration));
}
/**
* @param duration a duration in milliseconds
*/
public Trigger(final TemporalAmount duration) {
+ this(new TemporalAmountAdapter(duration));
+ }
+
+ private Trigger(final TemporalAmountAdapter duration) {
super(TRIGGER, new Factory());
- setDuration(duration);
+ this.duration = duration;
}
/**
@@ -188,7 +190,7 @@ public Trigger(final TemporalAmount duration) {
*/
@Deprecated
public Trigger(final ParameterList aList, final Dur duration) {
- this(aList, TemporalAmountAdapter.from(duration).getDuration());
+ this(aList, TemporalAmountAdapter.from(duration));
}
/**
@@ -196,8 +198,12 @@ public Trigger(final ParameterList aList, final Dur duration) {
* @param duration a duration in milliseconds
*/
public Trigger(final ParameterList aList, final TemporalAmount duration) {
+ this(aList, new TemporalAmountAdapter(duration));
+ }
+
+ private Trigger(final ParameterList aList, final TemporalAmountAdapter duration) {
super(TRIGGER, aList, new Factory());
- setDuration(duration);
+ this.duration = duration;
}
/**
@@ -244,7 +250,7 @@ public final void validate() throws ValidationException {
ParameterValidator.getInstance().assertNullOrEqual(Value.DATE_TIME,
getParameters());
- if (getDateTime() == null) {
+ if (getDate() == null) {
throw new ValidationException("DATE-TIME value not specified");
}
}
@@ -267,9 +273,9 @@ public final void setValue(final String aValue) {
try {
super.setValue(aValue);
duration = null;
- } catch (ParseException pe) {
+ } catch (DateTimeParseException pe) {
duration = TemporalAmountAdapter.parse(aValue);
- super.setDateTime(null);
+ super.setDate(null);
}
}
@@ -286,8 +292,8 @@ public final String getValue() {
/**
* @param dateTime The dateTime to set.
*/
- public final void setDateTime(final Instant dateTime) {
- setDate(dateTime);
+ public void setDate(final Instant dateTime) {
+ super.setDate(dateTime);
duration = null;
getParameters().replace(Value.DATE_TIME);
}
@@ -297,7 +303,7 @@ public final void setDateTime(final Instant dateTime) {
*/
public final void setDuration(final TemporalAmount duration) {
this.duration = new TemporalAmountAdapter(duration);
- super.setDateTime(null);
+ super.setDate(null);
// duration is the default value type for Trigger..
if (getParameter(Parameter.VALUE) != null) {
getParameters().replace(Value.DURATION);
@@ -311,8 +317,7 @@ public Factory() {
super(TRIGGER);
}
- public Property createProperty(final ParameterList parameters, final String value)
- throws IOException, URISyntaxException, ParseException {
+ public Property createProperty(final ParameterList parameters, final String value) {
return new Trigger(parameters, value);
}
diff --git a/src/main/java/net/fortuna/ical4j/model/property/UtcProperty.java b/src/main/java/net/fortuna/ical4j/model/property/UtcProperty.java
index eed475acd..b622d72b1 100644
--- a/src/main/java/net/fortuna/ical4j/model/property/UtcProperty.java
+++ b/src/main/java/net/fortuna/ical4j/model/property/UtcProperty.java
@@ -93,6 +93,7 @@ public void setDateTime(final Instant dateTime) {
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("deprecation")
public void setTimeZone(TimeZone timezone) {
throw new UnsupportedOperationException("Cannot set timezone for UTC properties");
}