Files
sf-app-platform/packages/utils/lib/src/date_utils.dart
JulianAlcala 42ec003b05 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
2026-04-07 16:59:38 +02:00

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;
}