deepdiff
deepdiff copied to clipboard
truncate_datetime - millisecond support
Is your feature request related to a problem? Please describe. Some databases (e.g. Mongo) store date/time to millisecond precision. Being able to truncate to this would be useful, and a very simple addition.
Describe the solution you'd like
Simply to be able to pass truncate_datetime='millisecond'.
Describe alternatives you've considered N/A
Additional context N/A
Hi @chriswyatt Can you please provide an example where truncate_datetime will be used for? Are you saying if the difference between 2 datetimes is less than a millisecond, we shouldn't report it as a diff then?
I was just thinking, work exactly the same way as the other truncate methods, but just down to the millisecond.
def datetime_normalize(truncate_datetime, obj)
...
elif truncate_datetime == 'millisecond':
obj = obj.replace(microsecond=(obj.microsecond // 1000) * 1000)
The BSON serializer that comes with PyMongo also floors the value in this way. This is useful for diffing datetimes before and after they get truncated by the BSON serializer. I'm just not interested in the microsecond part as it gets thrown away.