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

In convert_date(), round the seconds values for more accuracy #38

Merged

Conversation

keitherskine
Copy link

First off, many thanks for creating this package @willtrnr . It's greatly appreciated.

This PR should address an issue I found when converting datetime values from the floats in an .xlsb spreadsheet. The date in question was July 4 2020 at 10:00:00. In Excel, this is stored as the floating point number 44016.416666666664. However, when convert_date() is used to retrieve the datetime, something unexpected happened:

>>> pyxlsb.convert_date(44016.416666666664)
datetime.datetime(2020, 7, 4, 9, 59, 59)  # the time should be 10:00:00, not 09:59:59

In convert_seconds() the seconds values are cast to integers with int. This truncates the seconds, whereas round will I believe return a better, more correct value:

>>> (44016.416666666664 % 1) * 24 * 60 * 60
35999.99999979045
>>> int((44016.416666666664 % 1) * 24 * 60 * 60)  # existing code
35999
>>> round((44016.416666666664 % 1) * 24 * 60 * 60)  # new code
36000

Hence, this PR changes the int to round so the nearest seconds value is returned, not the lower one.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 3, 2021

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.16%.

Quality metrics Before After Change
Complexity 3.18 ⭐ 3.18 ⭐ 0.00
Method Length 48.00 ⭐ 48.67 ⭐ 0.67 👎
Working memory 6.91 🙂 6.91 🙂 0.00
Quality 76.23% 76.07% -0.16% 👎
Other metrics Before After Change
Lines 23 23 0
Changed files Quality Before Quality After Quality Change
pyxlsb/init.py 76.23% ⭐ 76.07% ⭐ -0.16% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@willtrnr
Copy link
Owner

willtrnr commented Nov 4, 2021

Good catch, round is indeed much better for the job. Thanks for the fix!

@willtrnr willtrnr self-assigned this Nov 4, 2021
@willtrnr willtrnr modified the milestones: v1.0.8, v1.0.x Nov 4, 2021
@willtrnr willtrnr merged commit fc89315 into willtrnr:v1.0.x Nov 4, 2021
@willtrnr willtrnr modified the milestones: v1.0.x, v1.0.9 Nov 4, 2021
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.

2 participants