Add convenient extensions for DateTime

This commit is contained in:
Ming Ming 2024-04-10 00:41:24 +08:00
parent 6281e6daff
commit b1f975c329
2 changed files with 14 additions and 0 deletions

View file

@ -2,3 +2,4 @@ library np_datetime;
export 'src/date.dart';
export 'src/time_range.dart';
export 'src/util.dart';

View file

@ -0,0 +1,13 @@
extension DateTimeExtension on DateTime {
/// Returns true if [this] occurs before or at the same moment as [other].
///
/// The comparison is independent
/// of whether the time is in UTC or in the local time zone.
bool isBeforeOrAt(DateTime other) => !isAfter(other);
/// Returns true if [this] occurs after or at the same moment as [other].
///
/// The comparison is independent
/// of whether the time is in UTC or in the local time zone.
bool isAfterOrAt(DateTime other) => !isBefore(other);
}