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

truncate_datetime - millisecond support #477

Open
chriswyatt opened this issue Aug 21, 2024 · 2 comments
Open

truncate_datetime - millisecond support #477

chriswyatt opened this issue Aug 21, 2024 · 2 comments

Comments

@chriswyatt
Copy link

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

@seperman
Copy link
Owner

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?

@chriswyatt
Copy link
Author

chriswyatt commented Aug 27, 2024

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.

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

No branches or pull requests

2 participants