mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Added flutter front-end
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class FriendlyDateFormatter {
|
||||
FriendlyDateFormatter();
|
||||
|
||||
String format(DateTime dateTime) {
|
||||
DateTime now = DateTime.now();
|
||||
Duration timeSince = now.difference(dateTime);
|
||||
DateTime today = DateTime(now.year, now.month, now.day);
|
||||
DateTime yesterday = DateTime(now.year, now.month, now.day - 1);
|
||||
DateTime dateTimeWithoutTime = DateTime(
|
||||
dateTime.year,
|
||||
dateTime.month,
|
||||
dateTime.day,
|
||||
);
|
||||
|
||||
if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago';
|
||||
if (dateTimeWithoutTime == today)
|
||||
return 'Today at ${DateFormat.Hm().format(dateTime)}';
|
||||
if (dateTimeWithoutTime == yesterday)
|
||||
return 'Yesterday at ${DateFormat.Hm().format(dateTime)}';
|
||||
|
||||
return DateFormat.yMMMMd().add_Hm().format(dateTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user