Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 haven't checked yet, but is usecs a whole number microseconds (before the round bit)? If so, seems like it could be simpler to just use that directly (and/or convert it to int from string)?
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.
You may be right. I haven't checked either!
I just wanted to leave the smallest footprint that passes for all million possible microsecond test cases.
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.
@dangnvang
i think that any of the changes should be fine, i added a new scenario and it looks ok as well 🙂
This test code:
Throws this output
So i think both cases are ok, what do you think?
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.
@agustinavarela:
I was thinking more like
usecs = int(usecs)
instead ofusecs = round(float('0.' + usecs) * 1e6)
Looking at the rest of the code, it looks like this is the conversion from MySQL datetimes to Python. The MySQL datetime format, when returned with microseconds (microseconds is the only fractional second supported it looks like), always has 6 numbers after the decimal point, so I think we're safe to go with using the more simple
int(usec)
conversion method.Regardless of which one we go with, this change should be tested with an actual DB where you write a datetime and read it back, ensuring that the microseconds portion of it is correctly converted in and out of MySQL.
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.
So I did some testing and determined that the MySQL documentation is a little misleading in some places.
In actuality, datetimes do have a fractional precision that you can specify for the number of decimal places to use. Thus, with testing actual use of the library, the
int(usec)
approach will not work because it's not always 6 characters as I previously inferred from other parts of the documentation.Keeping it as
round(float('0.' + usecs) * 1e6)
should be ok!Sorry for the confusion!
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.
@dangnvang thanks so much for checking that! :)