Skip to content

CustomRPC Fix#4228

Open
SwezyDev wants to merge 1 commit into
Vendicated:mainfrom
SwezyDev:main
Open

CustomRPC Fix#4228
SwezyDev wants to merge 1 commit into
Vendicated:mainfrom
SwezyDev:main

Conversation

@SwezyDev
Copy link
Copy Markdown

Fix TimestampMode.TIME not resetting after 24h in CustomRPC.
The timestamp was only calculated once, causing the timer to continue past midnight.

Now it recalculates based on the start of the current day so it correctly resets at 00:00 without needing timers or scheduling.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a midnight reset mechanism for the Custom RPC plugin to ensure that the 'current time' timestamp remains accurate across multiple days. It introduces a scheduling function using setTimeout and updates the plugin's lifecycle methods to manage this timer. Review feedback suggests simplifying the start-of-day calculation using the idiomatic Date.setHours method and removing redundant timeout clearing in the stop function, as this logic is already encapsulated within setRpc.

Comment on lines +132 to +136
const getElapsedToday = () => {
const now = new Date();
return now.getHours() * 3600 + now.getMinutes() * 60 + now.getSeconds();
};
activity.timestamps = { start: Date.now() - getElapsedToday() * 1000 };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The calculation for the start of the current day can be significantly simplified using the built-in Date.setHours method. This approach is more idiomatic, readable, and avoids manual arithmetic that ignores milliseconds, ensuring the timestamp starts exactly at 00:00:00.000.

            activity.timestamps = { start: new Date().setHours(0, 0, 0, 0) };

Comment on lines +249 to +255
stop: () => {
if (midnightTimeout !== null) {
clearTimeout(midnightTimeout);
midnightTimeout = null;
}
setRpc(true);
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The manual clearing of midnightTimeout in the stop function is redundant. The setRpc function, which is called immediately after, already performs this exact cleanup at the start of its execution.

    stop: () => setRpc(true),

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