https://github.com/danreynolds/date_tools
Tools for managing dates in Dart including a DateInterval implementation
https://github.com/danreynolds/date_tools
dart datetime flutter hacktoberfest
Last synced: 7 months ago
JSON representation
Tools for managing dates in Dart including a DateInterval implementation
- Host: GitHub
- URL: https://github.com/danreynolds/date_tools
- Owner: danReynolds
- License: mit
- Created: 2023-10-26T15:45:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-06T22:25:10.000Z (10 months ago)
- Last Synced: 2025-04-06T23:25:20.491Z (10 months ago)
- Topics: dart, datetime, flutter, hacktoberfest
- Language: Dart
- Homepage: https://pub.dev/packages/date_tools
- Size: 50.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Date Tools
Tools for working with dates. Currently just a [DateInterval] implementation.
### Date Intervals
The [DateInterval] API makes it easier to work with common date intervals like days, months and years. You can check the start/end of intervals,
move to previous and next intervals, and generate sequences of intervals.
```dart
/// The interval defaults to the [DateTime.now()], but we'll provide a date to make it clear.
final now = DateTime(2023, 10, 26);
print(DateInterval.day(now).start()); // DateTime:<2023-10-26 00:00:00.000000Z>
print(DateInterval.day(now).end()); // DateTime:<2023-10-26 23:59:59.999999Z>
print(DateInterval.year(now).next().start); // DateTime:<2024-01-01 00:00:00.000000Z>
print(DateInterval.month(now).generate(4).toList());
// DateInterval(interval: month, start: 2023-10-01 00:00:00.000, end: 2023-10-31 23:59:59.999999)
// DateInterval(interval: month, start: 2023-11-01 00:00:00.000, end: 2023-11-30 23:59:59.999999)
// DateInterval(interval: month, start: 2023-12-01 00:00:00.000, end: 2023-12-31 23:59:59.999999)
// DateInterval(interval: month, start: 2024-01-01 00:00:00.000, end: 2023-01-31 23:59:59.999999)
print(DateInterval.day(now).range(now.add(2.days)).toList());
// DateInterval(interval: day, start: 2023-10-26 00:00:00.000, end: 2023-10-26 23:59:59.999999)
// DateInterval(interval: day, start: 2023-10-27 00:00:00.000, end: 2023-10-27 23:59:59.999999)
// DateInterval(interval: day, start: 2023-10-28 00:00:00.000, end: 2023-10-28 23:59:59.999999)
print(DateInterval.month(now).spans(now)); // true
print(DateInterval.month(now).subtract(1).spans(now)); // false
```
More tools will be added in the future. Happy coding!