Skip to content

fix(filelisting): replace SimpleDateFormat with DateTimeFormatter and Instant#338

Open
Avanish Jha (Kingjha13) wants to merge 3 commits into
ktorio:mainfrom
Kingjha13:main
Open

fix(filelisting): replace SimpleDateFormat with DateTimeFormatter and Instant#338
Avanish Jha (Kingjha13) wants to merge 3 commits into
ktorio:mainfrom
Kingjha13:main

Conversation

@Kingjha13

Copy link
Copy Markdown

Summary

This PR modernizes date handling in the filelisting sample and fixes several issues.

Changes

  • Replace SimpleDateFormat with DateTimeFormatter
  • Replace java.util.Date with java.time.Instant
  • Fix date pattern from YYYY to yyyy
  • Remove usage of request.location() which is no longer available in Ktor 3.x
  • Restore CSS rendering by adding the missing unary + in the HTML DSL

Why

  • SimpleDateFormat is not thread-safe and can produce incorrect results when shared across concurrent requests.
  • DateTimeFormatter is immutable and thread-safe.
  • YYYY uses week-based years and can display incorrect years around New Year boundaries.
  • Instant is the modern Java time API and integrates cleanly with DateTimeFormatter.
  • request.location() causes compilation issues in Ktor 3.x.

Verification

  • Built successfully with ./gradlew build
  • Verified application startup with ./gradlew run
  • Confirmed file listing and info pages render correctly.

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 78aa6158-d33d-44e9-aaaf-bbb8479e9244

📥 Commits

Reviewing files that changed from the base of the PR and between c89f051 and 0889322.

📒 Files selected for processing (2)
  • filelisting/gradle.properties
  • filelisting/src/main/kotlin/io/ktor/samples/filelisting/FileListingApplication.kt

Walkthrough

File listing sample is updated to use Kotlin 2.3.21 and modernizes date/time handling. The change replaces SimpleDateFormat with DateTimeFormatter and updates the FileInfo data model to use java.time.Instant instead of java.util.Date for file timestamps. The /info HTML output removes request.location() and clarifies CSS formatting.

Changes

File Listing Modernization

Layer / File(s) Summary
Kotlin compiler version update
filelisting/gradle.properties
Kotlin Gradle property updated from 2.3.0 to 2.3.21.
Date/time API modernization
filelisting/src/main/kotlin/io/ktor/samples/filelisting/FileListingApplication.kt
Imports updated to use java.time classes (Instant, ZoneId, DateTimeFormatter). FileInfo data class field date changed from java.util.Date to java.time.Instant. File listing logic in listSuspend updated to construct FileInfo with Instant.ofEpochMilli(it.lastModified()) for files and Instant.now() for parent entries. DateTimeFormatter configured with Locale.ENGLISH and ZoneId.systemDefault() replaces SimpleDateFormat.
HTML/CSS presentation updates
filelisting/src/main/kotlin/io/ktor/samples/filelisting/FileListingApplication.kt
CSS string in the /info page reformatted with explicit triple-quoted literal and trimIndent(). request.location() output row removed from the info HTML table with a comment noting its removal in Ktor 3.x.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 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
Title check ✅ Passed The title accurately describes the main changes: replacing SimpleDateFormat with DateTimeFormatter and using Instant instead of java.util.Date, which aligns with the file changes and PR objectives.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, providing clear rationale for each modification and verification steps taken.
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

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.

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.

1 participant