File size: 565 Bytes
78013c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

library;

import 'package:intl/intl.dart';

extension DateTimeFormatting on DateTime {
  
  String get formattedDate => DateFormat.yMMMMd().format(this);

  String get formattedDateTime => '$formattedDate at ${DateFormat.jm().format(this)}';

  String get shortDate => DateFormat('E, MMM d').format(this);

  bool isSameDay(DateTime other) =>
      year == other.year && month == other.month && day == other.day;
}

extension StringFormatting on String {
  
  String truncate(int maxLength) =>
      length <= maxLength ? this : '${substring(0, maxLength)}…';
}