TF-148 Add data layer for cleanup email cache
This commit is contained in:
@@ -15,6 +15,12 @@ extension DateTimeExtension on DateTime {
|
||||
final now = DateTime.now();
|
||||
return now.year == this.year;
|
||||
}
|
||||
|
||||
int daysBetween(DateTime from) {
|
||||
from = DateTime(from.year, from.month, from.day);
|
||||
final to = DateTime(year, month, day);
|
||||
return (to.difference(from).inHours / 24).round().abs();
|
||||
}
|
||||
}
|
||||
|
||||
extension DateTimeNullableExtension on DateTime? {
|
||||
|
||||
@@ -72,6 +72,8 @@ dependencies:
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
test: 1.16.8
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:core/core.dart';
|
||||
|
||||
void main() {
|
||||
group('datetime test', () {
|
||||
|
||||
test('daysBetween should return 1 day2 when day2 > day1', () async {
|
||||
DateTime date1 = DateTime.parse("2021-10-20 12:59:12.000");
|
||||
DateTime date2 = DateTime.parse("2021-10-21 10:29:03.000");
|
||||
|
||||
expect(date2.daysBetween(date1), 1);
|
||||
});
|
||||
|
||||
test('daysBetween should return 1 days when day1 > day2', () async {
|
||||
DateTime date1 = DateTime.parse("2021-10-22 12:59:12.000");
|
||||
DateTime date2 = DateTime.parse("2021-10-21 10:29:03.000");
|
||||
|
||||
expect(date2.daysBetween(date1), 1);
|
||||
});
|
||||
|
||||
test('daysBetween should return 0 day when day1 = day2', () async {
|
||||
DateTime date1 = DateTime.parse("2021-10-22 12:59:12.000");
|
||||
DateTime date2 = DateTime.parse("2021-10-22 10:29:03.000");
|
||||
|
||||
expect(date2.daysBetween(date1), 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user