jama5262 / jiffy

Jiffy is a Flutter (Android, IOS and Web) date time package for parsing, manipulating, querying and formatting dates
https://pub.dev/packages/jiffy
MIT License
576 stars 124 forks source link

Fix difference between two date times with asFloat param #267

Closed samip77 closed 5 months ago

samip77 commented 5 months ago

What does this PR do? The difference between two date times had wrong test case which was hiding the actual issue.

The documentation for diff function mentioned:

  /// The optional [asFloat] parameter determines whether to return the
  /// difference as a floating-point number. The default value is [false].
  ///

but the asFloat default value was true

  num diff(Jiffy jiffy, {Unit unit = Unit.microsecond, bool asFloat = true}) {
    return _display.diff(dateTime, jiffy.dateTime, unit, asFloat);
  }

and in the inner function the logic was wrong

return asFloat ? _asFloor(diff) : diff;

Along with that the test case has wrong assumption, because of which it passed the test.

Issue Reference

Fixes #

Types of changes

Screenshots

If applicable, add screenshots to help explain your problem.

Checklist

Additional Information

jama5262 commented 5 months ago

@samip77 Thanks for the contribution, will take a look

samip77 commented 5 months ago

@samip77 Thanks for the contribution, will take a look

Thanks, I had missed few test cases. updated them as well.