Skip to content

Fix ProgressSync last-synced date showing 22 Jan 1970 - #159

Open
vishae wants to merge 1 commit into
kyxap:developfrom
vishae:fix/progress-sync-timestamp-ms-to-s
Open

Fix ProgressSync last-synced date showing 22 Jan 1970#159
vishae wants to merge 1 commit into
kyxap:developfrom
vishae:fix/progress-sync-timestamp-ms-to-s

Conversation

@vishae

@vishae vishae commented Jul 11, 2026

Copy link
Copy Markdown

Summary

column_date_synced was showing dates around 22 Jan 1970 instead of the real sync time.

progress_data['timestamp'] comes directly from the KOReader sync server's GET /syncs/progress/:document response. The reference server implementation (koreader/koreader-sync-server, syncs_controller.lua) stores this via Lua's os.time(), i.e. plain Unix seconds:

local timestamp = os.time()
...
redis:hmset(key, { ..., [self.timestamp_field] = timestamp })

action.py was dividing that value by 1000 before calling datetime.fromtimestamp(), which is the correct conversion for milliseconds, not seconds:

datetime.fromtimestamp(progress_data['timestamp']/1000, tz=local_tz)

Today's real epoch time is roughly 1.78 billion seconds. Dividing that by 1000 gives ~1.78 million seconds, which lands about 20 days after the Unix epoch — displayed as 22 Jan 1970. This reproduces consistently regardless of which KOReader client wrote the progress, since the server always uses its own current time on write and this plugin's date math is what mangles it afterward.

Fix

Removed the /1000progress_data['timestamp'] is already in seconds, which is what datetime.fromtimestamp() expects.

Test plan

  • make test (via pytest tests/): 14/16 pass; the 2 pre-existing failures (test_version_match, test_version_tuple_match) are unrelated version-string sync checks that also fail on unmodified develop HEAD.
  • make lint (via pylint): 9.68/10 (above the 9.5 threshold), no new warnings on the changed line.
  • Confirmed against the reference sync server's source that timestamp is written as Unix seconds, not milliseconds.

progress_data['timestamp'] comes straight from the KOReader sync
server's GET /syncs/progress response, which stores it via Lua's
os.time() (Unix seconds) - see koreader/koreader-sync-server's
syncs_controller.lua. Dividing that by 1000 before passing it to
datetime.fromtimestamp() treats a seconds value as milliseconds,
producing a timestamp ~1000x too small: today's real epoch time
(~1.78 billion seconds) becomes ~1.78 million seconds, which lands
about 20 days after the epoch - displayed as 22 Jan 1970.
@vishae

vishae commented Jul 30, 2026

Copy link
Copy Markdown
Author

this PR fixes #163

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.

2 participants