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

Bug: Miscalculation by one day #97

Closed
MeirKlemp opened this issue Feb 10, 2023 · 3 comments · Fixed by #96
Closed

Bug: Miscalculation by one day #97

MeirKlemp opened this issue Feb 10, 2023 · 3 comments · Fixed by #96

Comments

@MeirKlemp
Copy link

MeirKlemp commented Feb 10, 2023

Hi, I recently started using your app to stop my addiction. Thank you for developing the app.

I found out that sometimes the time since last relapse is one day more than the real value.

How to reproduce the bug:

  1. Create a new addiction with time later than now.
  2. Go to the addictions list and look at the time since relapse of the added addiction.

Version v10.0.0

Screenshots:
Screenshot_20230210-091646(1).png
Screenshot_20230210-091707.png
Screenshot_20230210-091719.png

@MeirKlemp
Copy link
Author

The bug is in this function:

fun Context.convertRangeToString(start: Long, end: Long = Instant.now().toEpochMilli()): String {

If for example, a day passed but not 24 hours since the start of the addiction, then the Period will say that a day passed, even though it didn't.

I have written a fix:

val durationToEndDay = Duration.between(startDate, startDate.toLocalDate().plusDays(1).atStartOfDay(ZoneOffset.UTC))
val d = if (durationToEndDay >= duration) (period.days % 7) else (period.days % 7 - 1)

Notice that ZoneOffset.UTC should be updated according to the local ZoneOffset.

@cubandle
Copy link
Contributor

Sorry about that, the patch for this issue is in process in a PR here (last commit specificially)

@MeirKlemp
Copy link
Author

Thank for fixing it.

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 a pull request may close this issue.

2 participants