Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time cut-off on time_ns #441

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pbabics
Copy link

@pbabics pbabics commented Feb 14, 2022

Hello,

currently time.time_ns is being updated to time cut to seconds, which is kind of weird behavior in regards to time.time which returns the decimal part.

Basically this should (hopefully) fix the issue with:
time.time_ns() / 1e9 != time.time()

@@ -180,7 +180,8 @@ def fake_time():
def fake_time_ns():
if _should_use_real_time():
return real_time_ns()
return int(int(fake_time()) * 1e9)
current_time = get_current_time()
return int(calendar.timegm(current_time.timetuple()) * 1_000_000_000 + current_time.microsecond * 1_000)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not return int(fake_time() * 1e9)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see – fake_time() * 1e9 could cause problems with precision and this integer multiplication won't.

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.

None yet

2 participants