/// Display formatting shared across screens. /// /// Ported from `com.rippr.ui.Format`. /// /// Timestamps come from the platform location fix, which is UTC epoch millis, so /// everything here converts to the device zone. Formatting in UTC would show a 21:00 /// ride as tomorrow. library; import 'package:intl/intl.dart'; import '../domain/models.dart'; // Built per call rather than cached in a top-level final. The Kotlin original captured // Locale.getDefault() once at class-init; doing the same here would freeze the format // for the process lifetime and ignore a locale change. DateFormat get _dayTime => DateFormat("EEE d MMM 'ยท' HH:mm"); DateFormat get _fileStamp => DateFormat('yyyy-MM-dd-HHmm'); String formatDateTime(int epochMillis) => _dayTime.format(DateTime.fromMillisecondsSinceEpoch(epochMillis)); String formatFileTimestamp(int epochMillis) => _fileStamp.format(DateTime.fromMillisecondsSinceEpoch(epochMillis)); /// A trip's own name, or a date-derived label when it has none. String tripLabel(Trip trip) => trip.name ?? formatDateTime(trip.startedAt); String formatDistance(double meters) => meters < 1000 ? '${meters.toInt()} m' : '${(meters / 1000).toStringAsFixed(1)} km'; String formatSpeed(double kmh) => '${kmh.toStringAsFixed(1)} km/h'; String formatElevation(double meters) => '${meters.toInt()} m';