-
Notifications
You must be signed in to change notification settings - Fork 246
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
use '5 years ago' instead of absolute timestamp #453
Conversation
Codecov Report
@@ Coverage Diff @@
## master #453 +/- ##
========================================
Coverage ? 90.1%
========================================
Files ? 144
Lines ? 27301
Branches ? 3929
========================================
Hits ? 24599
Misses ? 1961
Partials ? 741 Continue to review full report at Codecov.
|
@@ -303,7 +306,7 @@ def json_for_cap(options, cap): | |||
"size": 1234, | |||
"metadata": { | |||
"tahoe": { | |||
"linkcrtime": 0.0, | |||
"linkcrtime": (time.time() - (5 * secs_per_year)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this also work around the boundary conditions? In particular, I notice that secs_per_year
is not always correct (since not all years have the same number of seconds). Will this cause the test to fail if run close enough to the year change-over? I guess any 5 year period will include either one or two leap years (intuitively; I haven't proven it). If it includes 1 leap year, then "5 years ago" is actually an additional 24 * 60 * 60
seconds ago. And if it includes 2 leap years, twice that addition.
So if this code runs on year X, Dec 31, 11PM then 5 * secs_per_year
ago is around year X-4, Jan 1, 11PM (or even Jan 2 for ranges including two leap years). This is still pretty close to 5 years ago but I haven't checked to see what the code that actually computes the "N years ago" string does.
If it behaves correctly, maybe it's still worth a comment somewhere around here that it's okay. And if not,
now = datetime.now()
then = now.replace(year=now.year-5)
five_year_interval = (now - then).total_seconds()
gives the true number of seconds for that particular 5 year window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also mock time.time()
during the code that measures the interval, to make it deterministic?
BTW I filed https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2901 before seeing this PR (I assumed it was already an end-of-year problem, but I guess it was a too-much-time-has-passed problem).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that we need to mock time
-- IMO, the "human readable output code" should output "5 years ago" regardless of a few seconds (or even days) difference in the interval length -- that said I haven't looked at what it actually does ...
Okay, I used @exarkun's more-exact method of computing the number of seconds in 5 years. I don't think we should mock |
fa5cbc4
to
5f00842
Compare
Fix a test broken by the slow march of time