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

Importer - Clockify Import duration rounding problems #4838

Closed
3 tasks done
bepixeld opened this issue May 5, 2024 · 3 comments
Closed
3 tasks done

Importer - Clockify Import duration rounding problems #4838

bepixeld opened this issue May 5, 2024 · 3 comments
Labels
bug plugin not meant to be implemented in the core, but could be a plugin

Comments

@bepixeld
Copy link

bepixeld commented May 5, 2024

Describe the issue

Importer Version: 2.10.0

The Clockify column Duration (decimal) is used to import the duration.
This leads to rounding errors in some constellations.

e.g. Start: 10:01; End: 10:42 = Duration 1:41h = 1.6833 in decimal.
duration-decimal-import-preview

After the import, the start/end is displayed correctly.
But the duration is displayed incorrectly as 1:40.
duration-decimal-import-result

The duration is stored in the database as 6059 seconds.
The correct value would be 6060 seconds

It seems that the importer always rounds down.
When formatting from seconds to h:m, it rounds down again.
Therefore, one minute is displayed too little.

Solution for me:
Use the Clockify column Duration (h) when importing.
In file ImportBundle/Importer/ClockifyTimesheetImporter.php (Line ~112)
Swap the lines case 'Duration (h)': and case 'Duration (decimal)': with each other.
duration-h-import-preview

This will import the duration correctly.
duration-h-import-result

I hope, this helps.
Or is there any better way?

I already tried

Kimai version

2.16.1

How do you run Kimai?

Virtual Server or alike

Which PHP version are you using?

8.2

Logfile

No response

Screenshots

No response

@bepixeld bepixeld added the bug label May 5, 2024
@kevinpapst
Copy link
Member

Can you try to switch your rounding rules in System > Preferences to 0 for all values and also change the rounding mode?
Kimai by default rounds minutes.

@bepixeld
Copy link
Author

bepixeld commented May 6, 2024

I have set all rounding rules to 0. Then made an import attempt for each rounding mode.
The problem remains with the wrong display of 1:40, instead of 1:41.

I have investigated the problem further:
When importing, the duration (decimal) is processed with the function Duration::parseDecimalFormat.
The duration is converted to seconds and then converted to int (round down).

$duration = 1.6833;
$duration = $duration * 3600; // 6059.88
return (int) $duration; // 6059

6059 is saved as the duration in the database.

As far as I have found, when displaying the duration in the Kimai timesheets, the function
Duration::format is used to format the duration.
Here too, only rounding down is used.

$seconds = 6059;
$hour = (int) floor($seconds / 3600); // 1
$minute = (int) floor((int) ($seconds / 60) % 60); // 40

The rounding rules from preferences are never used here.
I think the easiest way to solve the problem is to use the Clockify field duration (h) for the duration column.
This eliminates the rounding problems for me.

Here is a test file so that you can try it yourself.

@kevinpapst
Copy link
Member

Thanks for the detailed input. I could reproduce the issue and your fix is working.
And yes, I was previously wrong, the rounding rules are not applied during import (which would be wrong anyway).
Its fixed in the latest release of the plugin.

@kevinpapst kevinpapst added the plugin not meant to be implemented in the core, but could be a plugin label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug plugin not meant to be implemented in the core, but could be a plugin
Projects
None yet
Development

No branches or pull requests

2 participants