Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix difference between two date times with asFloat param #267

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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