Skip to content

fix(chart): use milliseconds for commit activity timestamps (fixes #1…#1651

Open
arnavsharma990 wants to merge 3 commits intoscalacenter:mainfrom
arnavsharma990:bug/1543-fix-commit-date
Open

fix(chart): use milliseconds for commit activity timestamps (fixes #1…#1651
arnavsharma990 wants to merge 3 commits intoscalacenter:mainfrom
arnavsharma990:bug/1543-fix-commit-date

Conversation

@arnavsharma990
Copy link
Copy Markdown
Contributor

Description

The "Commit Activity" chart on project pages was displaying dates starting from 1970 (Unix Epoch). This was caused by a unit mismatch: the server was providing a timestamp in Seconds, but the frontend client (and Chart.js) expected Milliseconds.

Changes

  • project.scala.html: Updated the template to explicitly convert the start date to Milliseconds using .toEpochMilli before rendering it to the HTML attribute.
  • Sparkline.scala: Updated the Scala.js frontend to parse the data-commit-activity-starting-day attribute using Instant.ofEpochMilli.

Verification

  • Ran ./cs launch sbt -- compile to ensure type safety for the new time conversions.
  • Verified that the logic now consistently uses Unix Milliseconds on both server and client.

@kannupriyakalra
Copy link
Copy Markdown
Collaborator

@arnavsharma990

It looks like the PR introduces (or surfaces) a regression in OldSearchApiTests. The failure comes from an UnsupportedOperationException: empty.max in ArtifactService.computeLatestVersion, specifically when calling max on an empty collection:

java.lang.UnsupportedOperationException: empty.max
  at scala.collection.IterableOnceOps.max
  ...
  at scaladex.server.service.ArtifactService.computeLatestVersion

This suggests that versions (or whatever sequence is being reduced) can be empty for some artifacts. Previously the test suite passed, so the new logic likely changed how versions are collected or filtered.

Could you:

  1. Add a guard for the empty case in computeLatestVersion (e.g., headOption, maxOption, or an explicit fallback)?
  2. Verify why OldSearchApiTests ends up with no versions, is this expected after your changes or an unintended side effect?
  3. Consider adding a small test case that exercises this empty-versions scenario to prevent regressions.

Once that’s addressed, the rest of the suite passes, so this should unblock the PR.

@kannupriyakalra kannupriyakalra requested a review from adpi2 December 5, 2025 02:17
Copilot AI review requested due to automatic review settings December 5, 2025 05:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses a timestamp unit mismatch causing the Commit Activity chart to display dates starting from 1970 (Unix Epoch) and additionally refactors the ArtifactService to handle cases where no versions are available.

Key changes:

  • Fixed timestamp conversion in commit activity chart from seconds to milliseconds
  • Refactored computeLatestVersion to return Option[Version] with proper empty sequence handling
  • Added comprehensive test coverage for the refactored computeLatestVersion method

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
modules/webclient/src/main/scala/scaladex/client/Sparkline.scala Updated frontend to parse commit activity timestamps as milliseconds using Instant.ofEpochMilli instead of ofEpochSecond
modules/template/src/main/twirl/scaladex/view/project/project.scala.html Updated template to convert timestamps to milliseconds using toEpochMilli instead of getEpochSecond
modules/server/src/main/scala/scaladex/server/service/ArtifactService.scala Changed computeLatestVersion to return Option[Version] and added proper handling for empty version sequences with appropriate logging
modules/server/src/test/scala/scaladex/server/service/ArtifactServiceTests.scala Added new test suite with comprehensive coverage for computeLatestVersion method including edge cases for empty sequences, stable/unstable version preferences

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arnavsharma990
Copy link
Copy Markdown
Contributor Author

Thanks @kannupriyakalra for guiding the approach to fix this,
I have fixed the empty sequence issue in ArtifactService.computeLatestVersion (now uses maxOption) and added unit tests covering empty and non-empty cases.

Verified locally: server/test, server/testOnly scaladex.server.service.ArtifactServiceTests, and testOnly scaladex.server.route.api.OldSearchApiTests all pass. PTAL.

@kannupriyakalra
Copy link
Copy Markdown
Collaborator

@arnavsharma990 a test case is failing, please check

@arnavsharma990
Copy link
Copy Markdown
Contributor Author

CI needed a tiny formatting tweak (import spacing). Fixed it now.

@arnavsharma990
Copy link
Copy Markdown
Contributor Author

@kannupriyakalra

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.

3 participants