mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-04-27 15:51:51 -05:00
33 lines
806 B
Dart
33 lines
806 B
Dart
import 'package:intl/intl.dart';
|
|
|
|
final _formatTime = DateFormat.jm();
|
|
final _formatMonthDate = DateFormat.MMMd();
|
|
final _formatYearMonthDate = DateFormat.yMMMd();
|
|
final _formatFullNoYear = DateFormat.MMMd().add_jm();
|
|
final _formatFull = DateFormat.yMMMd().add_jm();
|
|
|
|
DateTime get _today {
|
|
final now = DateTime.now();
|
|
return DateTime(now.year, now.month, now.day);
|
|
}
|
|
|
|
extension Formats on DateTime {
|
|
String formatShort() {
|
|
final today = _today;
|
|
if (isAfter(today)) {
|
|
return _formatTime.format(this);
|
|
}
|
|
if (year == today.year) {
|
|
return _formatMonthDate.format(this);
|
|
}
|
|
return _formatYearMonthDate.format(this);
|
|
}
|
|
|
|
String formatLong() {
|
|
if (year == _today.year) {
|
|
return _formatFullNoYear.format(this);
|
|
}
|
|
return _formatFull.format(this);
|
|
}
|
|
}
|