Verified Commit 11e6b247 authored by WorldTeacher's avatar WorldTeacher
Browse files

fix(progress): better timestamp handling for past timestamps

parent 9f90cd67
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -6264,10 +6264,9 @@ function BookloreSync:evaluateKoreaderProgressDirection(remote, local_state)

    if remote_pct < local_pct then
        if remote_ts > 0 and local_ts > 0 then
            if remote_ts < local_ts then
                return "backward"
            if remote_ts <= local_ts then
                return "equal"
            end
            return "forward"
        end
        return "backward"
    end
+18 −0
Original line number Diff line number Diff line
@@ -33,6 +33,24 @@ describe("BookloreSync helper methods", function()
    assert.are.equal("1h 1m 1s", plugin:formatDuration(3661))
  end)

  it("treats stale remote progress that is behind local as equal", function()
    local direction = plugin:evaluateKoreaderProgressDirection(
      { percentage = 0.04, progress = "40", timestamp = 1715004000 },
      { percentage = 0.045, progress = "45", timestamp = 1715007600 }
    )

    assert.are.equal("equal", direction)
  end)

  it("keeps backward direction when remote progress is behind but newer", function()
    local direction = plugin:evaluateKoreaderProgressDirection(
      { percentage = 0.04, progress = "40", timestamp = 1715007600 },
      { percentage = 0.045, progress = "45", timestamp = 1715004000 }
    )

    assert.are.equal("backward", direction)
  end)

  it("rounds progress using configured decimal places", function()
    plugin.progress_decimal_places = 2
    assert.are.equal(33.33, plugin:roundProgress(33.333))