- 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
11 lines
471 B
Dart
11 lines
471 B
Dart
/// 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;
|
|
}
|