Skip to content

Commit

Permalink
Updated groupware templates
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jan 5, 2024
1 parent dbd7aa8 commit 901b5fe
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/org/ical4j/template/groupware/Anniversary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.ical4j.template.groupware;

import net.fortuna.ical4j.extensions.property.Repeats;
import net.fortuna.ical4j.model.component.VEvent;
import org.ical4j.template.AbstractTemplate;

import java.time.LocalDate;

import static net.fortuna.ical4j.model.DateTimePropertyModifiers.DTSTART;
import static net.fortuna.ical4j.model.RecurrencePropertyModifiers.RRULE;

/**
* Creates a recurring {@link VEvent} representing a birthday/anniversary, etc.
*/
public class Anniversary extends AbstractTemplate<VEvent> {

private Repeats<?> schedule;

private LocalDate date;

public Anniversary() {
super(VEvent.class);
}

public Anniversary(Class<? extends VEvent> typeClass) {
super(typeClass);
}

public <T extends VEvent> Anniversary(T prototype) {
super(prototype.getClass());
setPrototype(prototype);
}

public Anniversary withRepeats(Repeats<?> schedule) {
this.schedule = schedule;
return this;
}

public Anniversary withDate(LocalDate date) {
this.date = date;
return this;
}

@Override
public VEvent apply(VEvent vEvent) {
vEvent.with(DTSTART, date);
vEvent.with(RRULE, schedule);
return vEvent;
}
}
83 changes: 83 additions & 0 deletions src/main/java/org/ical4j/template/groupware/Observance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.ical4j.template.groupware;

import net.fortuna.ical4j.extensions.property.Repeats;
import net.fortuna.ical4j.model.DateList;
import net.fortuna.ical4j.model.DateTimePropertyModifiers;
import net.fortuna.ical4j.model.DescriptivePropertyModifiers;
import net.fortuna.ical4j.model.RecurrencePropertyModifiers;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.property.immutable.ImmutableTransp;
import org.ical4j.template.AbstractTemplate;

import java.time.LocalDate;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.List;

/**
* Creates an (optionally recurring) date-based {@link VEvent} representing a public holiday or
* other observance.
*
* Includes observances from <a href="https://www.un.org/en/observances/list-days-weeks"> UN International Days</a>.
*/
public class Observance extends AbstractTemplate<VEvent> {

private String title;

private Temporal start;

private Temporal end;

private List<LocalDate> dates = new ArrayList<>();

private Repeats<LocalDate> schedule;

public Observance() {
super(VEvent.class);
}

public Observance(Class<? extends VEvent> typeClass) {
super(typeClass);
}

public <T extends VEvent> Observance(T prototype) {
super(prototype.getClass());
setPrototype(prototype);
}

public Observance title(String title) {
this.title = title;
return this;
}

public Observance start(Temporal date) {
this.start = date;
return this;
}

public Observance end(Temporal date) {
this.end = date;
return this;
}

public Observance date(LocalDate date) {
dates.add(date);
return this;
}

public Observance repeats(Repeats<LocalDate> schedule) {
this.schedule = schedule;
return this;
}

@Override
public VEvent apply(VEvent vEvent) {
vEvent.replace(ImmutableTransp.TRANSPARENT);
vEvent.with(DescriptivePropertyModifiers.SUMMARY, title);
vEvent.with(DateTimePropertyModifiers.DTSTART, start);
vEvent.with(DateTimePropertyModifiers.DTEND, end);
vEvent.with(RecurrencePropertyModifiers.RRULE, schedule);
vEvent.with(RecurrencePropertyModifiers.RDATE, new DateList<>(dates));
return vEvent;
}
}

0 comments on commit 901b5fe

Please sign in to comment.