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

fix Incorrect DiffInMonths calculation #59 #60

Conversation

rendyreivaldy25
Copy link

added condition check if diffInMonths > 0, so diffInMonths can work properly.
issue #59

@Santos-Luis
Copy link

@tlfbrito @gracoes

@tlfbrito
Copy link

tlfbrito commented Jan 1, 2021

@rendyreivaldy25
Thanks for your contribution.

I know it's not your fault, but before merging this we need to fix the CI/CD (current Travis) first.
We want to migrate this to Github Actions.

@rendyreivaldy25
Copy link
Author

@rendyreivaldy25
Thanks for your contribution.

I know it's not your fault, but before merging this we need to fix the CI/CD (current Travis) first.
We want to migrate this to Github Actions.

glad to help. please contact me if my code has a problem.

@tlfbrito
Copy link

@rendyreivaldy25 can you rebase with master?
We migrated the CI to Github Actions and we should now be able to execute the tests again.

@rendyreivaldy25
Copy link
Author

@tlfbrito I am so sorry. I was so busy until I forgot to check this issue. I made some changes again because in my last works, different bugs appeared. Right now it should be running okay. Please kindly check if there are other bugs. Thanks

Comment on lines +1207 to +1213
if carb.Timestamp() < c.Timestamp() {
remainingTime = int(c.DiffInHours(carb, true))
totalHours = carb.DaysInMonth() * hoursPerDay
} else {
remainingTime = int(carb.DiffInHours(c, true))
totalHours = c.DaysInMonth() * hoursPerDay
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you isolate this in a function? and return instead of using if-else statement?

Suggested change
if carb.Timestamp() < c.Timestamp() {
remainingTime = int(c.DiffInHours(carb, true))
totalHours = carb.DaysInMonth() * hoursPerDay
} else {
remainingTime = int(carb.DiffInHours(c, true))
totalHours = c.DaysInMonth() * hoursPerDay
}
remainingTime, totalHours = calculateDiffInTimeAndHours(c, carb)
// ...
func calculateDiffInTimeAndHours(c, carb * Carbon) (int64, int64) {
if carb.Timestamp() < c.Timestamp() {
return int(c.DiffInHours(carb, true)), carb.DaysInMonth() * hoursPerDay
}
return int(carb.DiffInHours(c, true)), c.DaysInMonth() * hoursPerDay
}
}

@rntdrts
Copy link
Contributor

rntdrts commented Oct 29, 2021

hi @rendyreivaldy25, just left you a suggestion! Let me know what you think :)

@rendyreivaldy25
Copy link
Author

hi @rendyreivaldy25, just left you a suggestion! Let me know what you think :)

Sorry for slow response, of course, I will fox that later. I will update to you soon

@codecov
Copy link

codecov bot commented Nov 4, 2021

Codecov Report

Merging #60 (7185764) into master (ce063dd) will increase coverage by 1.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
+ Coverage   89.11%   90.17%   +1.05%     
==========================================
  Files           3        3              
  Lines         634      641       +7     
==========================================
+ Hits          565      578      +13     
+ Misses         44       39       -5     
+ Partials       25       24       -1     
Impacted Files Coverage Δ
carbon.go 91.23% <100.00%> (+0.77%) ⬆️
translator.go 65.51% <0.00%> (+6.89%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c77b65...7185764. Read the comment docs.

@rntdrts
Copy link
Contributor

rntdrts commented Apr 16, 2022

Due to lack of activity - Fixing this on #74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants