-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbd7aa8
commit 901b5fe
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/org/ical4j/template/groupware/Anniversary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
83
src/main/java/org/ical4j/template/groupware/Observance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |