19 lines
616 B
Dart
19 lines
616 B
Dart
class SCConversationTimeFormatter {
|
|
const SCConversationTimeFormatter._();
|
|
|
|
static String format(DateTime date, {DateTime? now}) {
|
|
final current = now ?? DateTime.now();
|
|
if (date.year != current.year) {
|
|
return '${date.year}-${_twoDigits(date.month)}-${_twoDigits(date.day)}';
|
|
}
|
|
|
|
final time = '${_twoDigits(date.hour)}.${_twoDigits(date.minute)}';
|
|
if (date.month != current.month || date.day != current.day) {
|
|
return '${_twoDigits(date.month)}-${_twoDigits(date.day)} $time';
|
|
}
|
|
return time;
|
|
}
|
|
|
|
static String _twoDigits(int value) => value.toString().padLeft(2, '0');
|
|
}
|