fix(player): 评论总数含回复并改用相对时间
This commit is contained in:
1 parent
22cb74ded4
commit
2659c29501
14 files changed
+212
-9
No files matched your search
@@ -0,0 +1,24 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
/// Formats a timestamp as a relative label, falling back to a compact local date.
|
||||
String formatRelativeDateTime(
|
||||
DateTime value,
|
||||
AppLocalizations l10n, {
|
||||
DateTime? now,
|
||||
}) {
|
||||
final localValue = value.toLocal();
|
||||
final localNow = (now ?? DateTime.now()).toLocal();
|
||||
final elapsed = localNow.difference(localValue);
|
||||
if (elapsed.isNegative || elapsed.inMinutes < 1) return l10n.justNow;
|
||||
if (elapsed.inMinutes < 60) return l10n.minutesAgo(elapsed.inMinutes);
|
||||
if (elapsed.inHours < 24) return l10n.hoursAgo(elapsed.inHours);
|
||||
if (localValue.year == localNow.year) {
|
||||
return '${_twoDigits(localValue.month)}-${_twoDigits(localValue.day)}';
|
||||
}
|
||||
return '${localValue.year}-${_twoDigits(localValue.month)}-'
|
||||
'${_twoDigits(localValue.day)}';
|
||||
}
|
||||
|
||||
String _twoDigits(int value) => value.toString().padLeft(2, '0');
|
||||
Reference in new issue
Block a user