From a2788083d2b1180c48e72093acb41e7b2e940695 Mon Sep 17 00:00:00 2001 From: Samip Shah Date: Tue, 26 Mar 2024 20:48:04 +1100 Subject: [PATCH] Fix difference between two date times with asFloat param --- lib/src/display.dart | 2 +- lib/src/jiffy.dart | 2 +- test/src/display_test.dart | 8 ++++---- test/src/jiffy_test.dart | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/src/display.dart b/lib/src/display.dart index fa76425..24153d2 100644 --- a/lib/src/display.dart +++ b/lib/src/display.dart @@ -135,7 +135,7 @@ class Display { break; } - return asFloat ? _asFloor(diff) : diff; + return asFloat ? diff : _asFloor(diff); } String _getLocaleOrdinal(Locale locale, int date) { diff --git a/lib/src/jiffy.dart b/lib/src/jiffy.dart index 1418767..b1adba7 100644 --- a/lib/src/jiffy.dart +++ b/lib/src/jiffy.dart @@ -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); } diff --git a/test/src/display_test.dart b/test/src/display_test.dart index 7b564d6..0515196 100644 --- a/test/src/display_test.dart +++ b/test/src/display_test.dart @@ -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'], @@ -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; diff --git a/test/src/jiffy_test.dart b/test/src/jiffy_test.dart index 28a9074..74679bb 100644 --- a/test/src/jiffy_test.dart +++ b/test/src/jiffy_test.dart @@ -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); @@ -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);