Skip to content

Commit

Permalink
chore: Rounding of epoch seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
patriknw committed Jan 17, 2025
1 parent 0804675 commit e390099
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ import org.slf4j.Logger
protected def appendEmptyBucketIfLastIsMissing(
buckets: IndexedSeq[Bucket],
toTimestamp: Instant): IndexedSeq[Bucket] = {
val startTimeOfLastBucket = (toTimestamp.getEpochSecond / 10) * 10
// db epoch seconds is rounding, but Instant is not
val startTimeOfLastBucket = (toTimestamp.plusMillis(500).getEpochSecond / 10) * 10
if (buckets.last.startTime != startTimeOfLastBucket)
buckets :+ Bucket(startTimeOfLastBucket, 0)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package akka.persistence.r2dbc.query

import java.time.Instant

import org.scalatest.wordspec.AnyWordSpecLike

import akka.actor.testkit.typed.scaladsl.LogCapturing
Expand Down Expand Up @@ -38,7 +40,8 @@ class BucketCountSpec
val slice2 = persistenceExt.sliceForPersistenceId(pid2)

val startTime = InstantFactory.now().minusSeconds(3600)
val bucketStartTime = (startTime.getEpochSecond / 10) * 10
// db epoch seconds is rounding, but Instant is not
val bucketStartTime = (startTime.plusMillis(500).getEpochSecond / 10) * 10

(0 until 10).foreach { i =>
writeEvent(slice1, pid1, 1 + i, startTime.plusSeconds(Buckets.BucketDurationSeconds * i), s"e1-$i")
Expand Down Expand Up @@ -69,7 +72,8 @@ class BucketCountSpec

val limit = 100
val startTime = InstantFactory.now().minusSeconds(3600)
val bucketStartTime = (startTime.getEpochSecond / 10) * 10
// db epoch seconds is rounding, but Instant is not
val bucketStartTime = (startTime.plusMillis(500).getEpochSecond / 10) * 10

(0 until 10).foreach { i =>
writeEvent(slice1, pid1, 1 + i, startTime.plusSeconds(Buckets.BucketDurationSeconds * i), s"e1-$i")
Expand Down

0 comments on commit e390099

Please sign in to comment.