mirror of
https://github.com/johrpan/memor.git
synced 2025-10-28 19:27:25 +01:00
Initial commit
This commit is contained in:
commit
4be8aa8ff5
47 changed files with 1577 additions and 0 deletions
41
lib/date_utils.dart
Normal file
41
lib/date_utils.dart
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Utilities for handling DateTime objects.
|
||||
extension DateUtils on DateTime {
|
||||
/// Create a new instance with identical values.
|
||||
DateTime copy() => DateTime(
|
||||
this.year,
|
||||
this.month,
|
||||
this.day,
|
||||
this.hour,
|
||||
this.minute,
|
||||
);
|
||||
|
||||
/// Create a new instance with the same date but a different time.
|
||||
DateTime copyWithTime(TimeOfDay time) => DateTime(
|
||||
this.year,
|
||||
this.month,
|
||||
this.day,
|
||||
time.hour,
|
||||
time.minute,
|
||||
);
|
||||
|
||||
/// Get a string representation of the represented day suitable for display.
|
||||
String get dateString {
|
||||
final now = DateTime.now();
|
||||
if (this.year == now.year && this.month == now.month) {
|
||||
if (this.day == now.day) {
|
||||
return 'Today';
|
||||
} else if (this.day == now.day + 1) {
|
||||
return 'Tomorrow';
|
||||
}
|
||||
}
|
||||
|
||||
final format = DateFormat.yMd();
|
||||
return format.format(this);
|
||||
}
|
||||
|
||||
/// Get the time of day represented by this object.
|
||||
TimeOfDay get timeOfDay => TimeOfDay.fromDateTime(this);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue