formatTime function
Implementation
String formatTime(DateTime date, {DateTime? clock}) {
final messages = _timeMessages;
clock = clock ?? DateTime.now();
var elapsed = clock.millisecondsSinceEpoch - date.millisecondsSinceEpoch;
final num seconds = elapsed / 1000;
final num minutes = seconds / 60;
final num hours = minutes / 60;
final num days = hours / 24;
String result;
if (seconds < 45) {
result = messages.lessThanOneMinute(seconds.round());
} else if (seconds < 90) {
result = messages.aboutAMinute(minutes.round());
} else if (minutes < 45) {
result = messages.minutes(minutes.round());
} else if (minutes < 90) {
result = messages.aboutAnHour(minutes.round());
} else if (hours < 24) {
result = messages.hours(minutes.round());
} else if (hours < 48) {
result = messages.aDay(minutes.round());
} else if (days < 360) {
result = messages.days(minutes.round());
} else {
result = messages.year(minutes.round());
}
return result;
}