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

Issue #390 #400

Closed
wants to merge 3 commits into from
Closed

Conversation

DamienBradleyDSP
Copy link

For #390

Small rework of human.nbt

-1 day -> 1 day ago
-2 hours -> 2 hours ago

@sharkdp
Copy link
Owner

sharkdp commented Mar 16, 2024

Thank you. From a quick glance, this seems to do more than just solve the problem with negative times. If so, can we please add regression tests for these other features/issues?

@DamienBradleyDSP
Copy link
Author

I can - I did run the -> Human function a fair bit post changes and the tests are passing in datetime_human_tests, I assume you mean just expand the number of unit tests that are already there to something more comprehensive?

@triallax
Copy link
Collaborator

I assume you mean just expand the number of unit tests that are already there to something more comprehensive?

Yes, that's generally good practice and what we expect people to do when contributing features to Numbat. :)

@DamienBradleyDSP
Copy link
Author

new tests added, let me know if there are any other cases in mind that you'd like to cover

Comment on lines 65 to 96
assert((-1 second -> human) == "1 second ago")
assert((-25 seconds -> human) == "25 seconds ago")
assert((-49.010 seconds -> human) == "49.010 seconds ago")

assert((-2.5 minute -> human) == "2 minutes + 30 seconds ago")
assert((-1 hour -> human) == "1 hour ago")
assert((-3 hour -> human) == "3 hours ago")
assert((-5.34 hour -> human) == "5 hours + 20 minutes + 24 seconds ago")
assert((-7.89 hour -> human) == "7 hours + 53 minutes + 24 seconds ago")
assert((-7.89 hour - 4 minutes -> human) == "7 hours + 57 minutes + 24 seconds ago")

assert((-1 day -> human) == "1 day ago")
assert((-4.6 days -> human) == "4 days + 14 hours + 23 minutes ago")
assert((-9.2345 days -> human) == "9 days + 5 hours + 37 minutes + 40.800 seconds ago")
assert((-9.2345 days + 52 hours -> human) == "7 days + 1 hour + 37 minutes + 40.800 seconds ago")

assert((-2 weeks -> human) == "14 days ago")
assert((-4.5 weeks -> human) == "31 days + 12 hours ago")
assert((-20.5 weeks -> human) == "143 days + 12 hours ago")

assert((-2.5 months -> human) == "76 days + 2 hours + 12 minutes + 39.385800 seconds ago")
assert((-2.5 years -> human) == "913 days + 2 hours + 31 minutes + 52.629600003 seconds ago")
assert((-10.5 decades -> human) == "38350 days ago")

assert((-25 ms -> human) == "0.025 seconds ago")
assert((-6400 ms -> human) == "6.400 seconds ago")

assert((-2500 µs -> human) == "0.002500 seconds ago")
assert((-40525 µs -> human) == "0.040525 seconds ago")

assert((-5147 ns -> human) == "0.000005147 seconds ago")
assert((-23s + 1234 ns -> human) == "22.999998766 seconds ago")
Copy link
Owner

Choose a reason for hiding this comment

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

The logic for "… ago" is relatively simple, right? In that case, we don't need to repeat all these tests here.

Copy link
Author

Choose a reason for hiding this comment

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

True but does protect against changes if someone switches the logic in some way in the future, and with the test base's overall speed I'd say it doesn't hurt anyone to keep these in

I can remove some of the more redundant cases though if you'd prefer

Copy link
Owner

Choose a reason for hiding this comment

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

True but does protect against changes if someone switches the logic in some way in the future, and with the test base's overall speed I'd say it doesn't hurt anyone to keep these in

Speed is not the matter, but humans are going to read those tests and wonder what they are for. I would really prefer if we strip down the negative-time-duration tests to one or two.

Copy link
Author

Choose a reason for hiding this comment

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

Updated as requested


# Implementation details:
# we skip hours/minutes/seconds for durations larger than 1000 days because:
# (a) we run into floating point precision problems at the nanosecond level at this point
# (b) for much larger numbers, we can't convert to DateTimes anymore
fn human_time_check_overflow(time: Time) =
Copy link
Owner

Choose a reason for hiding this comment

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

can we please _-prefix this as well?

@sharkdp
Copy link
Owner

sharkdp commented May 15, 2024

I am still not sure what this PR brings in addition to the "… ago" handling of negative durations. For now, I'm going to close this in favor of #425. But please feel free to comment here and we can reopen it.

@sharkdp sharkdp closed this May 15, 2024
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

3 participants