diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/general/DateTimeRendering.java b/user-interface/src/main/java/life/qbic/datamanager/views/general/DateTimeRendering.java new file mode 100644 index 000000000..b5cc5b516 --- /dev/null +++ b/user-interface/src/main/java/life/qbic/datamanager/views/general/DateTimeRendering.java @@ -0,0 +1,31 @@ +package life.qbic.datamanager.views.general; + +import java.time.Instant; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +/** + * Date Time Rendering + * + *

A collection of utility methods to render instants in a harmonised way throughout the + * application.

+ * + * @since 1.7.0 + */ +public class DateTimeRendering { + + private static final String DATE_TIME_PATTERN = "dd.MM.yyyy HH:mm"; + + /** + * Formats an {@link Instant} in "dd.MM.yyyy HH:mm". + * + * @param instant the instant to format + * @return the formatted instant + * @since 1.7.0 + */ + public static String simple(Instant instant) { + var formatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN).withZone(ZoneId.systemDefault()); + return formatter.format(instant); + } + +} diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/projects/overview/components/ProjectCollectionComponent.java b/user-interface/src/main/java/life/qbic/datamanager/views/projects/overview/components/ProjectCollectionComponent.java index b9068f8d6..08d7ad6f5 100644 --- a/user-interface/src/main/java/life/qbic/datamanager/views/projects/overview/components/ProjectCollectionComponent.java +++ b/user-interface/src/main/java/life/qbic/datamanager/views/projects/overview/components/ProjectCollectionComponent.java @@ -24,6 +24,7 @@ import life.qbic.application.commons.SortOrder; import life.qbic.datamanager.views.account.UserAvatar.UserAvatarGroupItem; import life.qbic.datamanager.views.general.Card; +import life.qbic.datamanager.views.general.DateTimeRendering; import life.qbic.datamanager.views.general.PageArea; import life.qbic.datamanager.views.general.Tag; import life.qbic.datamanager.views.general.Tag.TagColor; @@ -200,7 +201,7 @@ public ProjectOverviewItem(ProjectOverview projectOverview) { Span header = createHeader(projectOverview.projectCode(), projectOverview.projectTitle()); add(header); Span lastModified = new Span( - String.format("Last modified on %s", projectOverview.lastModified())); + String.format("Last modified on %s", DateTimeRendering.simple(projectOverview.lastModified()))); lastModified.addClassName("tertiary"); add(lastModified); projectDetails.addClassName("details"); diff --git a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/info/ProjectSummaryComponent.java b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/info/ProjectSummaryComponent.java index 4beb0c251..8a19cfec5 100644 --- a/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/info/ProjectSummaryComponent.java +++ b/user-interface/src/main/java/life/qbic/datamanager/views/projects/project/info/ProjectSummaryComponent.java @@ -37,6 +37,7 @@ import life.qbic.datamanager.views.Context; import life.qbic.datamanager.views.TagFactory; import life.qbic.datamanager.views.account.UserAvatar.UserAvatarGroupItem; +import life.qbic.datamanager.views.general.DateTimeRendering; import life.qbic.datamanager.views.general.CollapsibleDetails; import life.qbic.datamanager.views.general.DetailBox; import life.qbic.datamanager.views.general.Heading; @@ -200,11 +201,6 @@ private static List loadWriteScope(Section[] sectio return Arrays.stream(sections).map(WriteScopeStrategy::new).toList(); } - private String formatDate(Instant date) { - var formatter = DateTimeFormatter.ofPattern(DATE_TIME_PATTERN).withZone(ZoneId.systemDefault()); - return formatter.format(date); - } - public void setContext(Context context) { this.context = Objects.requireNonNull(context); var projectId = context.projectId() @@ -556,7 +552,7 @@ private void buildHeaderSection(ProjectOverview projectOverview) { sectionContent.add(createTags(projectOverview)); header.setSectionNote(new SectionNote( - "Last modified on %s".formatted(formatDate(projectOverview.lastModified())))); + "Last modified on %s".formatted(DateTimeRendering.simple(projectOverview.lastModified())))); headerSection.setHeader(header); headerSection.setContent(sectionContent); }