Skip to content

Add WebConfig with Instant to String converter and update templates for consistent date formatting#107

Merged
Tyreviel merged 2 commits into
mainfrom
improvement/DateTimeFormatting
Apr 27, 2026
Merged

Add WebConfig with Instant to String converter and update templates for consistent date formatting#107
Tyreviel merged 2 commits into
mainfrom
improvement/DateTimeFormatting

Conversation

@mattknatt

@mattknatt mattknatt commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Standardized date and time formatting across the application. All creation timestamps for cases and employees, patient record creation dates, and document upload dates now display in a consistent and uniform format throughout the entire system, providing improved usability and a better user experience when navigating between different views and sections.

@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@mattknatt has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 48 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f3ca7eb3-f5ad-4afc-af80-f62826c5e519

📥 Commits

Reviewing files that changed from the base of the PR and between 1d97c73 and 22942be.

📒 Files selected for processing (2)
  • src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java
  • src/main/resources/templates/audit/list.html
📝 Walkthrough

Walkthrough

This PR introduces a Spring configuration class that registers a global type converter for formatting Instant objects to human-readable strings, and updates multiple Thymeleaf templates to leverage this conversion for consistently displaying timestamp fields across the application.

Changes

Cohort / File(s) Summary
Spring Configuration
src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java
Introduces new WebConfig class with a @Bean method that provides a Converter<Instant, String> using a fixed date-time formatter (yyyy-MM-dd HH:mm) in the Europe/Stockholm time zone.
Thymeleaf Templates
src/main/resources/templates/cases/closed.html, src/main/resources/templates/cases/detail.html, src/main/resources/templates/cases/list.html, src/main/resources/templates/employees/list.html, src/main/resources/templates/patients/list.html
Updates timestamp field expressions (e.g., createdAt, uploadedAt) from ${...} to ${{...}} syntax in th:text bindings to utilize the centralized Instant to String conversion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #22: Modifies the same Thymeleaf templates for timestamp rendering, indicating related work on date-time formatting across templates.

Poem

🐰 Time flies swift, but now it's clear and bright,
With formats set to Stockholm's time just right,
No more confusion in the template land,
Instant to strings—a converter so grand!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: introducing a WebConfig class with an Instant-to-String converter and updating multiple templates to use consistent date formatting syntax.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improvement/DateTimeFormatting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mattknatt mattknatt linked an issue Apr 27, 2026 that may be closed by this pull request

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java (1)

14-15: Consider externalizing the timezone (and pattern) to configuration.

Hardcoding Europe/Stockholm works for this deployment, but binds presentation policy to source. Exposing it as a property (e.g. app.display.zone, app.display.datetime-pattern) makes it trivially adjustable per-environment and clearer in intent.

♻️ Suggested refactor
-    private static final DateTimeFormatter DISPLAY_FORMAT =
-            DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").withZone(ZoneId.of("Europe/Stockholm"));
-
-    `@Bean`
-    public Converter<Instant, String> instantToStringConverter() {
-        return DISPLAY_FORMAT::format;
-    }
+    `@Bean`
+    public Converter<Instant, String> instantToStringConverter(
+            `@Value`("${app.display.datetime-pattern:yyyy-MM-dd HH:mm}") String pattern,
+            `@Value`("${app.display.zone:Europe/Stockholm}") String zone) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(zone));
+        return formatter::format;
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java`
around lines 14 - 15, The DISPLAY_FORMAT DateTimeFormatter is hardcoded to
"yyyy-MM-dd HH:mm" and ZoneId.of("Europe/Stockholm"); change this to read two
config properties (e.g. app.display.datetime-pattern and app.display.zone) with
sensible defaults, remove the static final constant and instead build the
DateTimeFormatter at runtime (e.g. in WebConfig constructor or a `@Bean` factory)
using DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(zone)), and use
`@Value` or Environment to inject the properties so presentation pattern and
timezone can be adjusted per-environment; keep the symbol names DISPLAY_FORMAT
and WebConfig to locate the change.
src/main/resources/templates/cases/detail.html (1)

103-103: Minor inconsistency: no null guard on doc.uploadedAt.

note.createdAt (line 78) is rendered with a th:if="${note.createdAt != null}" guard, but doc.uploadedAt here has none. The ConversionService does treat null as null (so this won't NPE — the cell would just render empty), but for visual consistency with the notes section, consider mirroring the same guard, or drop the guard from line 78 if note.createdAt is in fact never null.

♻️ Suggested change
-                    <span th:text="${{doc.uploadedAt}}">Date</span>
+                    <span th:if="${doc.uploadedAt != null}" th:text="${{doc.uploadedAt}}">Date</span>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/resources/templates/cases/detail.html` at line 103, The template is
inconsistent: doc.uploadedAt is rendered without a null guard while
note.createdAt uses th:if="${note.createdAt != null}"; update the template to
mirror the notes behavior by adding the same conditional guard around the
doc.uploadedAt span (or alternatively remove the th:if from note.createdAt if
you can guarantee note.createdAt is never null) so both date renderings use the
same null-handling approach; target the span rendering doc.uploadedAt and the
span for note.createdAt when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java`:
- Around line 14-20: The template audit/list.html currently formats e.occurredAt
with "#temporals.format(e.occurredAt, 'yyyy-MM-dd HH:mm:ss', 'UTC')" which
conflicts with the new application-wide DISPLAY_FORMAT and
instantToStringConverter (yyyy-MM-dd HH:mm, Europe/Stockholm); if e.occurredAt
is an Instant, replace the inline formatter with the unified rendering by
changing the template to output ${e.occurredAt} so it uses
instantToStringConverter, otherwise if seconds/UTC are intentionally required
for audit traceability, add a clear comment above the template line explaining
why the inline '#temporals.format(..., "yyyy-MM-dd HH:mm:ss", "UTC")' is
deliberately different to avoid future confusion.

---

Nitpick comments:
In
`@src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java`:
- Around line 14-15: The DISPLAY_FORMAT DateTimeFormatter is hardcoded to
"yyyy-MM-dd HH:mm" and ZoneId.of("Europe/Stockholm"); change this to read two
config properties (e.g. app.display.datetime-pattern and app.display.zone) with
sensible defaults, remove the static final constant and instead build the
DateTimeFormatter at runtime (e.g. in WebConfig constructor or a `@Bean` factory)
using DateTimeFormatter.ofPattern(pattern).withZone(ZoneId.of(zone)), and use
`@Value` or Environment to inject the properties so presentation pattern and
timezone can be adjusted per-environment; keep the symbol names DISPLAY_FORMAT
and WebConfig to locate the change.

In `@src/main/resources/templates/cases/detail.html`:
- Line 103: The template is inconsistent: doc.uploadedAt is rendered without a
null guard while note.createdAt uses th:if="${note.createdAt != null}"; update
the template to mirror the notes behavior by adding the same conditional guard
around the doc.uploadedAt span (or alternatively remove the th:if from
note.createdAt if you can guarantee note.createdAt is never null) so both date
renderings use the same null-handling approach; target the span rendering
doc.uploadedAt and the span for note.createdAt when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1bbb4ac7-7dd2-44cd-8e77-3554c7e377f4

📥 Commits

Reviewing files that changed from the base of the PR and between 8456fd6 and 1d97c73.

📒 Files selected for processing (6)
  • src/main/java/org/example/projektarendehantering/infrastructure/config/WebConfig.java
  • src/main/resources/templates/cases/closed.html
  • src/main/resources/templates/cases/detail.html
  • src/main/resources/templates/cases/list.html
  • src/main/resources/templates/employees/list.html
  • src/main/resources/templates/patients/list.html

@Tyreviel
Tyreviel merged commit f74ca19 into main Apr 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix date/time formatting

2 participants