Skip to content

Commit

Permalink
[ISSUE-273] Use floating points to calculate relative time
Browse files Browse the repository at this point in the history
  • Loading branch information
jama5262 committed May 12, 2024
1 parent bbf07ee commit 4a818ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/src/display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ class Display {
}

final seconds =
diff(firstDateTime, secondDateTime, Unit.second, false).abs();
diff(firstDateTime, secondDateTime, Unit.second, true).abs();
final minutes =
diff(firstDateTime, secondDateTime, Unit.minute, false).abs();
final hours = diff(firstDateTime, secondDateTime, Unit.hour, false).abs();
final days = diff(firstDateTime, secondDateTime, Unit.day, false).abs();
final months = diff(firstDateTime, secondDateTime, Unit.month, false).abs();
final years = diff(firstDateTime, secondDateTime, Unit.year, false).abs();
diff(firstDateTime, secondDateTime, Unit.minute, true).abs();
final hours = diff(firstDateTime, secondDateTime, Unit.hour, true).abs();
final days = diff(firstDateTime, secondDateTime, Unit.day, true).abs();
final months = diff(firstDateTime, secondDateTime, Unit.month, true).abs();
final years = diff(firstDateTime, secondDateTime, Unit.year, true).abs();

String result;

Expand Down
21 changes: 21 additions & 0 deletions test/src/display_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:jiffy/jiffy.dart';
import 'package:jiffy/src/display.dart';
import 'package:jiffy/src/enums/unit.dart';
import 'package:jiffy/src/getter.dart';
Expand Down Expand Up @@ -323,6 +324,16 @@ List<Map<String, dynamic>> toAsRelativeDateTimeTestData() {
'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45),
'expectedToAsRelativeDateTime': 'in a minute'
},
{
'firstDateTime': DateTime(2024, 1, 1, 2, 0, 0),
'secondDateTime': DateTime(2024, 1, 1, 1, 58, 5),
'expectedToAsRelativeDateTime': '2 minutes ago'
},
{
'firstDateTime': DateTime(2024, 1, 1, 2, 0, 0),
'secondDateTime': DateTime(2024, 1, 1, 1, 58, 31),
'expectedToAsRelativeDateTime': 'a minute ago'
},
{
'firstDateTime': DateTime(1997, 10, 23, 12, 11, 23),
'secondDateTime': DateTime(1997, 10, 23, 12, 11, 22),
Expand Down Expand Up @@ -513,6 +524,16 @@ List<Map<String, dynamic>> fromAsRelativeDateTimeTestData() {
'secondDateTime': DateTime(1997, 10, 23, 12, 11, 0),
'expectedFromAsRelativeDateTime': 'in a minute'
},
{
'firstDateTime': DateTime(2024, 1, 1, 2, 0, 0),
'secondDateTime': DateTime(2024, 1, 1, 1, 58, 5),
'expectedFromAsRelativeDateTime': 'in 2 minutes'
},
{
'firstDateTime': DateTime(2024, 1, 1, 2, 0, 0),
'secondDateTime': DateTime(2024, 1, 1, 1, 58, 31),
'expectedFromAsRelativeDateTime': 'in a minute'
},
{
'firstDateTime': DateTime(1997, 10, 23, 12, 11, 0),
'secondDateTime': DateTime(1997, 10, 23, 12, 11, 45),
Expand Down

0 comments on commit 4a818ac

Please sign in to comment.