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 a278808
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 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
8 changes: 4 additions & 4 deletions test/src/display_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ void main() {

group('Test diff between two datetime', () {
for (var testData in diffDateTimeTestData()) {
test('Should successfully get difference between two datetime', () {
test('Should successfully get difference when float is disabled', () {
// Setup
final asFloat = true;
final asFloat = false;

// Execute
final actualDifference = underTest.diff(testData['firstDateTime'],
Expand All @@ -167,12 +167,12 @@ void main() {
});
}

test('Should successfully get difference when float is disabled', () {
test('Should successfully get difference between two datetime', () {
// Setup
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 a278808

Please sign in to comment.