Get start and end date time of an event formatted using a pattern
parent
b034d7d321
commit
ae2d3b57ea
|
|
@ -18,13 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.pages.models;
|
package org.librecms.pages.models;
|
||||||
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
import java.time.LocalDateTime;
|
||||||
import org.librecms.contentsection.ContentItem;
|
|
||||||
import org.librecms.contenttypes.Event;
|
|
||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -32,6 +28,10 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contenttypes.Event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -48,15 +48,13 @@ public class EventModel implements ProcessesContentItem {
|
||||||
|
|
||||||
private boolean initialized;
|
private boolean initialized;
|
||||||
|
|
||||||
private final DateTimeFormatter isoDateTimeFormatter;
|
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
|
|
||||||
private String startDateTime;
|
private LocalDateTime startDateTime;
|
||||||
|
|
||||||
private String endDateTime;
|
private LocalDateTime endDateTime;
|
||||||
|
|
||||||
private String eventDate;
|
private String eventDate;
|
||||||
|
|
||||||
|
|
@ -66,8 +64,6 @@ public class EventModel implements ProcessesContentItem {
|
||||||
|
|
||||||
public EventModel() {
|
public EventModel() {
|
||||||
initialized = false;
|
initialized = false;
|
||||||
isoDateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME
|
|
||||||
.withZone(ZoneId.systemDefault());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
|
@ -85,19 +81,97 @@ public class EventModel implements ProcessesContentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getStartDateTime() {
|
public LocalDateTime getStartDateTime() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
||||||
return startDateTime;
|
return startDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the start date of the event represented by this model formatted
|
||||||
|
* using the provided pattern. The pattern MUST be a valid pattern for
|
||||||
|
* {@link DateTimeFormatter#ofPattern(java.lang.String) }.
|
||||||
|
*
|
||||||
|
* @param pattern The pattern to use for formatting the release date.
|
||||||
|
*
|
||||||
|
* @return The formatted release date.
|
||||||
|
*/
|
||||||
|
public String getStartDateTime(final String pattern) {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return Optional
|
||||||
|
.ofNullable(startDateTime)
|
||||||
|
.map(
|
||||||
|
dateTime -> DateTimeFormatter
|
||||||
|
.ofPattern(
|
||||||
|
pattern,
|
||||||
|
globalizationHelper.getNegotiatedLocale()
|
||||||
|
)
|
||||||
|
.withZone(ZoneId.systemDefault())
|
||||||
|
.format(dateTime)
|
||||||
|
)
|
||||||
|
.orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStartDateTimeAsString() {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return Optional
|
||||||
|
.ofNullable(endDateTime)
|
||||||
|
.map(
|
||||||
|
dateTime -> DateTimeFormatter.ISO_DATE_TIME
|
||||||
|
.withZone(ZoneId.systemDefault())
|
||||||
|
.format(dateTime)
|
||||||
|
)
|
||||||
|
.orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getEndDateTime() {
|
public LocalDateTime getEndDateTime() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
||||||
return endDateTime;
|
return endDateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the end date of the event represented by this model formatted
|
||||||
|
* using the provided pattern. The pattern MUST be a valid pattern for
|
||||||
|
* {@link DateTimeFormatter#ofPattern(java.lang.String) }.
|
||||||
|
*
|
||||||
|
* @param pattern The pattern to use for formatting the release date.
|
||||||
|
*
|
||||||
|
* @return The formatted release date.
|
||||||
|
*/
|
||||||
|
public String getEndDateTime(final String pattern) {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return Optional
|
||||||
|
.ofNullable(endDateTime)
|
||||||
|
.map(
|
||||||
|
dateTime -> DateTimeFormatter
|
||||||
|
.ofPattern(
|
||||||
|
pattern,
|
||||||
|
globalizationHelper.getNegotiatedLocale()
|
||||||
|
)
|
||||||
|
.withZone(ZoneId.systemDefault())
|
||||||
|
.format(dateTime)
|
||||||
|
)
|
||||||
|
.orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndDateTimeAsString() {
|
||||||
|
contentItemModel.init();
|
||||||
|
|
||||||
|
return Optional
|
||||||
|
.ofNullable(endDateTime)
|
||||||
|
.map(
|
||||||
|
dateTime -> DateTimeFormatter.ISO_DATE_TIME
|
||||||
|
.withZone(ZoneId.systemDefault())
|
||||||
|
.format(dateTime)
|
||||||
|
)
|
||||||
|
.orElse("");
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String getEventDate() {
|
public String getEventDate() {
|
||||||
contentItemModel.init();
|
contentItemModel.init();
|
||||||
|
|
@ -139,14 +213,20 @@ public class EventModel implements ProcessesContentItem {
|
||||||
.orElse("");
|
.orElse("");
|
||||||
startDateTime = Optional
|
startDateTime = Optional
|
||||||
.ofNullable(event.getStartDate())
|
.ofNullable(event.getStartDate())
|
||||||
.map(Date::toInstant)
|
.map(
|
||||||
.map(isoDateTimeFormatter::format)
|
startDate -> LocalDateTime.from(
|
||||||
.orElse("");
|
startDate.toInstant().atZone(ZoneId.systemDefault())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orElse(null);
|
||||||
endDateTime = Optional
|
endDateTime = Optional
|
||||||
.ofNullable(event.getEndDate())
|
.ofNullable(event.getEndDate())
|
||||||
.map(Date::toInstant)
|
.map(
|
||||||
.map(isoDateTimeFormatter::format)
|
endDate -> LocalDateTime.from(
|
||||||
.orElse("");
|
endDate.toInstant().atZone(ZoneId.systemDefault())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orElse(null);
|
||||||
eventDate = Optional
|
eventDate = Optional
|
||||||
.ofNullable(event.getEventDate())
|
.ofNullable(event.getEventDate())
|
||||||
.map(globalizationHelper::getValueFromLocalizedString)
|
.map(globalizationHelper::getValueFromLocalizedString)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue