From 9cfac6db5c4c8b92027993678ceb14e922069c8f Mon Sep 17 00:00:00 2001 From: Samip Shah Date: Tue, 26 Mar 2024 20:44:55 +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 | 4 ++-- test/src/jiffy_test.dart | 4 ++-- 4 files changed, 6 insertions(+), 6 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..f65268b 100644 --- a/test/src/display_test.dart +++ b/test/src/display_test.dart @@ -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'], @@ -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; 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);