refactor(tracking): tighten sf_tracking package
- Lazy-init sfTracking to avoid touching Firebase at import time - DRY SfTrackingRepository with a single _broadcast helper - Drop empty DashboardTracking, fix double step_completed in device_setup - Move yearsBetween to packages/utils - Add 5 unit tests for SfTrackingRepository - Strip noisy comments from mixins and view models
This commit is contained in:
10
packages/utils/lib/src/date_utils.dart
Normal file
10
packages/utils/lib/src/date_utils.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
/// Returns the number of full years between [from] and [to], using the
|
||||
/// classic "have we already passed the birthday this year?" rule. Returns
|
||||
/// 0 if [from] is in the future relative to [to].
|
||||
int yearsBetween(DateTime from, DateTime to) {
|
||||
var years = to.year - from.year;
|
||||
final hasNotReachedAnniversary =
|
||||
to.month < from.month || (to.month == from.month && to.day < from.day);
|
||||
if (hasNotReachedAnniversary) years -= 1;
|
||||
return years < 0 ? 0 : years;
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export 'src/date_utils.dart';
|
||||
export 'src/size_utils.dart';
|
||||
export 'src/test.dart';
|
||||
|
||||
Reference in New Issue
Block a user