Skip to content

Commit

Permalink
make initialOnsetUTC an instance variable to fix perf issue #506
Browse files Browse the repository at this point in the history
  • Loading branch information
db82407 committed Jul 14, 2021
1 parent 3703831 commit 23595e9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/main/java/net/fortuna/ical4j/model/component/Observance.java
Expand Up @@ -79,6 +79,7 @@ public abstract class Observance extends Component {
private DateTime[] onsetsDates;
// private Map onsets = new TreeMap();
private Date initialOnset = null;
private DateTime initialOnsetUTC = null;

/**
* Used for parsing times in a UTC date-time representation.
Expand Down Expand Up @@ -156,19 +157,20 @@ public final void validate(final boolean recurse) throws ValidationException {
*/
public final Date getLatestOnset(final Date date) {

DateTime initialOnsetUTC;
// get first onset without adding TZFROM as this may lead to a day boundary
// change which would be incompatible with BYDAY RRULES
// we will have to add the offset to all cacheable onsets
try {
DtStart dtStart = (DtStart) getRequiredProperty(Property.DTSTART);
initialOnsetUTC = calculateOnset(dtStart.getDate());
} catch (ParseException | ConstraintViolationException e) {
Logger log = LoggerFactory.getLogger(Observance.class);
log.error("Unexpected error calculating initial onset", e);
// XXX: is this correct?
// return null;
initialOnsetUTC = new DateTime(new java.util.Date(0));
if (initialOnsetUTC == null) {
try {
DtStart dtStart = (DtStart) getRequiredProperty(Property.DTSTART);
initialOnsetUTC = calculateOnset(dtStart.getDate());
} catch (ParseException | ConstraintViolationException e) {
Logger log = LoggerFactory.getLogger(Observance.class);
log.error("Unexpected error calculating initial onset", e);
// XXX: is this correct?
// return null;
initialOnsetUTC = new DateTime(new java.util.Date(0));
}
}

if (initialOnset == null) {
Expand Down

0 comments on commit 23595e9

Please sign in to comment.