Skip to content

Commit

Permalink
Enable harmonised date time rendering (#946)
Browse files Browse the repository at this point in the history
Because it is just annoying to present users with a ISO8601 unformatted timestamp.
  • Loading branch information
sven1103 authored Dec 11, 2024
1 parent b6e68c8 commit 12a958d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package life.qbic.datamanager.views.general;

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
* <b>Date Time Rendering</b>
*
* <p>A collection of utility methods to render instants in a harmonised way throughout the
* application.</p>
*
* @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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,11 +201,6 @@ private static List<? extends UserScopeStrategy> 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()
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 12a958d

Please sign in to comment.