Skip to content

Commit

Permalink
Fix difference between two date times with asFloat param
Browse files Browse the repository at this point in the history
  • Loading branch information
samip77 committed Mar 26, 2024
1 parent bd758c8 commit 9cfac6d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/src/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Display {
break;
}

return asFloat ? _asFloor(diff) : diff;
return asFloat ? diff : _asFloor(diff);
}

String _getLocaleOrdinal(Locale locale, int date) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/jiffy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ class Jiffy {
/// print('Difference in days: $diffInDays');
/// // output: Difference in days: -14
/// ```
num diff(Jiffy jiffy, {Unit unit = Unit.microsecond, bool asFloat = true}) {
num diff(Jiffy jiffy, {Unit unit = Unit.microsecond, bool asFloat = false}) {
return _display.diff(dateTime, jiffy.dateTime, unit, asFloat);
}

Expand Down
4 changes: 2 additions & 2 deletions test/src/display_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void main() {
for (var testData in diffDateTimeTestData()) {
test('Should successfully get difference between two datetime', () {
// Setup
final asFloat = true;
final asFloat = false;

// Execute
final actualDifference = underTest.diff(testData['firstDateTime'],
Expand All @@ -172,7 +172,7 @@ void main() {
final firstDateTime = DateTime(2022, 12, 5);
final secondDateTime = DateTime(2022, 12, 8);
final unit = Unit.week;
final asFloat = false;
final asFloat = true;

final expectedDifference = -0.42857142857142855;

Expand Down
4 changes: 2 additions & 2 deletions test/src/jiffy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ void main() {

// Execute
final actualDifference =
underTest.diff(jiffyFrom, unit: Unit.month, asFloat: false);
underTest.diff(jiffyFrom, unit: Unit.month, asFloat: true);

// Verify
expect(actualDifference, expectedDifference);
Expand All @@ -913,7 +913,7 @@ void main() {

// Execute
final actualDifference =
underTest.diff(jiffyFrom, unit: Unit.month, asFloat: true);
underTest.diff(jiffyFrom, unit: Unit.month, asFloat: false);

// Verify
expect(actualDifference, expectedDifference);
Expand Down

0 comments on commit 9cfac6d

Please sign in to comment.