-
Notifications
You must be signed in to change notification settings - Fork 54
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
Time Precision #22
Comments
This should be/might be handled by Time.Equal? If the things being compared have an
Are you using |
Yes, I'm using time.Time. The only way I currently see is to use an own type with an own Equal method? I wouldn't want to change all time.Time like this as an artifact of testing. Is there a better way? |
Sorry for slow reply. I'm not sure how to handle this. |
It is. But: From the original message:
So if you create a One option is to use One way that could maybe be done is if your library goes through all the fields by itself and you have access to all objects, you could truncate one or both time objects just before comparing them based on the precision that's configured for the comparison. |
Thanks, I see the issue and I agree: if one wants 1000 ns == 1234 ns to be true, then sure. But I'll have to poke at the code to see if it's possible to do this without too much special-case code. The workaround, which maybe the OP already does, is to explicitly test/round time values retrieved from the db, then zero out the time values when comparing against all the other expected values. Or, if the input can be controlled, then provide known time values that store and retrieve exactly. |
Hi,
would it be possible to add an option "TimePrecision" analog to "FloatPrecision" which would permit to Truncate the times before comparison.
Reason:
I use deep.Equal to test my Database Interface. I compare the stored Struct with the original one (which contains timestamps). The DB I use (postgres) has a time resolution of Microsecond whereas the golang time.Time has a resolution of Nanosecond. Being able to truncate the timestamps would permit to compare those two.
thanks for considering
The text was updated successfully, but these errors were encountered: