Initial commit

This commit is contained in:
Elias Projahn 2020-05-21 20:25:25 +02:00
commit 4be8aa8ff5
47 changed files with 1577 additions and 0 deletions

41
lib/date_utils.dart Normal file
View 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);
}