-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wrapped): update to support multiple years!
- Loading branch information
1 parent
99bde9b
commit a0fde1c
Showing
4 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
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
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
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,30 @@ | ||
package xyz.nucleoid.extras; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import java.util.Calendar; | ||
import java.util.GregorianCalendar; | ||
|
||
public record WrappedEvent( | ||
int year, | ||
GregorianCalendar start, | ||
GregorianCalendar end | ||
) { | ||
@SuppressWarnings("MagicConstant") | ||
public static final Codec<GregorianCalendar> CALENDAR_CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.INT.fieldOf("year").forGetter(cal -> cal.get(Calendar.YEAR)), | ||
Codec.INT.fieldOf("month").forGetter(cal -> cal.get(Calendar.MONTH) + 1), | ||
Codec.INT.fieldOf("date").forGetter(cal -> cal.get(Calendar.DAY_OF_MONTH)) | ||
).apply(instance, (year, month, dayOfMonth) -> new GregorianCalendar(year, month - 1, dayOfMonth))); | ||
|
||
public static final Codec<WrappedEvent> CODEC = RecordCodecBuilder.create(instance -> instance.group( | ||
Codec.INT.fieldOf("year").forGetter(WrappedEvent::year), | ||
CALENDAR_CODEC.fieldOf("start").forGetter(WrappedEvent::start), | ||
CALENDAR_CODEC.fieldOf("end").forGetter(WrappedEvent::end) | ||
).apply(instance, WrappedEvent::new)); | ||
|
||
public boolean isDuring(Calendar cal) { | ||
return cal.equals(this.start) || cal.equals(this.end) || (cal.after(this.start) && cal.before(this.end)); | ||
} | ||
} |
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