Skip to content

Fix time cut-off on time_ns#441

Open
pbabics wants to merge 1 commit into
spulec:masterfrom
pbabics:fix/time-ns-precision
Open

Fix time cut-off on time_ns#441
pbabics wants to merge 1 commit into
spulec:masterfrom
pbabics:fix/time-ns-precision

Conversation

@pbabics

@pbabics pbabics commented Feb 14, 2022

Copy link
Copy Markdown

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()

@pbabics pbabics force-pushed the fix/time-ns-precision branch from 087e1c6 to c370104 Compare February 14, 2022 09:55
Comment thread freezegun/api.py
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
Copy Markdown
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)?

@marcinsulikowski marcinsulikowski Sep 15, 2022

Copy link
Copy Markdown
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.

2 participants