mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 02:19:09 +02:00
v1.0.4
- Added `yesterday` and `tomorrow` extensions to `DateTime` Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
## 1.0.4
|
||||||
|
|
||||||
|
- Added `yesterday` and `tomorrow` extensions to `DateTime`
|
||||||
|
|
||||||
## 1.0.3+2
|
## 1.0.3+2
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ void main() {
|
|||||||
debugPrint("$today"); // true
|
debugPrint("$today"); // true
|
||||||
debugPrint("$notToday"); // false
|
debugPrint("$notToday"); // false
|
||||||
|
|
||||||
|
final DateTime yesterday = DateTime(0).yesterday;
|
||||||
|
final DateTime tomorrow = DateTime(0).tomorrow;
|
||||||
|
|
||||||
|
debugPrint("Yesterday: $yesterday");
|
||||||
|
debugPrint("Tomorrow: $tomorrow");
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
const String? nullString = null;
|
const String? nullString = null;
|
||||||
const String emptyString = " ";
|
const String emptyString = " ";
|
||||||
|
|||||||
@@ -109,3 +109,34 @@ extension FirstDayOfWeek on DateTime {
|
|||||||
return firstDay;
|
return firstDay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An extension that provides convenient getters to retrieve the start of
|
||||||
|
/// yesterday and tomorrow for `DateTime`.
|
||||||
|
///
|
||||||
|
/// This extension simplifies the process of getting the start of the previous day
|
||||||
|
/// or the next day relative to the current date and time.
|
||||||
|
extension YesterdayAndTomorrow on DateTime {
|
||||||
|
/// Returns a `DateTime` representing the start of the previous day (yesterday).
|
||||||
|
///
|
||||||
|
/// This getter subtracts one day from the current date and time, then returns
|
||||||
|
/// the result with the time set to the start of the day (00:00:00).
|
||||||
|
///
|
||||||
|
/// Example usage:
|
||||||
|
/// ```dart
|
||||||
|
/// DateTime yesterday = DateTime(0).yesterday;
|
||||||
|
/// ```
|
||||||
|
DateTime get yesterday =>
|
||||||
|
DateTime.now().subtract(const Duration(days: 1)).startOfDay;
|
||||||
|
|
||||||
|
/// Returns a `DateTime` representing the start of the next day (tomorrow).
|
||||||
|
///
|
||||||
|
/// This getter adds one day to the current date and time, then returns the
|
||||||
|
/// result with the time set to the start of the day (00:00:00).
|
||||||
|
///
|
||||||
|
/// Example usage:
|
||||||
|
/// ```dart
|
||||||
|
/// DateTime tomorrow = DateTime(0).tomorrow;
|
||||||
|
/// ```
|
||||||
|
DateTime get tomorrow =>
|
||||||
|
DateTime.now().add(const Duration(days: 1)).startOfDay;
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: arcane_helper_utils
|
name: arcane_helper_utils
|
||||||
description: Provides a variety of helpful utilities and extensions for Flutter
|
description: Provides a variety of helpful utilities and extensions for Flutter
|
||||||
and Dart.
|
and Dart.
|
||||||
version: 1.0.3+2
|
version: 1.0.4
|
||||||
repository: https://github.com/hanskokx/arcane_helper_utils
|
repository: https://github.com/hanskokx/arcane_helper_utils
|
||||||
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user