Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TimesResolver implements NoticeResolver<TitleTimes> {

private static final TemporalAmountParser<Duration> DURATION_PARSER = DurationParser.TIME_UNITS;
private static final String TIMES_FORMAT = "%s %s %s";
private static final String ZERO_TIME = "0s";

@Override
public NoticeKey<TitleTimes> noticeKey() {
Expand All @@ -35,9 +36,9 @@ public void send(Audience audience, ComponentSerializer<Component, Component, St
@Override
public NoticeSerdesResult serialize(TitleTimes content) {
return new NoticeSerdesResult.Single(String.format(TIMES_FORMAT,
DURATION_PARSER.format(content.fadeIn()),
DURATION_PARSER.format(content.stay()),
DURATION_PARSER.format(content.fadeOut())
this.formatDuration(content.fadeIn()),
this.formatDuration(content.stay()),
this.formatDuration(content.fadeOut())
));
}

Expand All @@ -62,4 +63,10 @@ public Optional<TitleTimes> deserialize(NoticeSerdesResult result) {
));
}

private String formatDuration(Duration duration) {
if (duration.isNegative() || duration.isZero()) {
return ZERO_TIME;
}
return DURATION_PARSER.format(duration);
}
}