https://github.com/westy92/const-date-time-range
A drop-in replacement for Dart's DateTimeRange class with a const constructor.
https://github.com/westy92/const-date-time-range
Last synced: about 2 months ago
JSON representation
A drop-in replacement for Dart's DateTimeRange class with a const constructor.
- Host: GitHub
- URL: https://github.com/westy92/const-date-time-range
- Owner: westy92
- License: mit
- Created: 2024-12-28T17:29:59.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-01-06T07:18:21.000Z (9 months ago)
- Last Synced: 2025-02-21T21:57:07.822Z (8 months ago)
- Language: Dart
- Size: 14.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# const_date_time_range
[](https://github.com/westy92/const-date-time-range/actions/workflows/github-actions.yml?query=branch%3Amain)
[](https://codecov.io/gh/westy92/const-date-time-range)
[](https://github.com/sponsors/westy92)A drop-in replacement for Dart's `DateTimeRange` class with `const` constructors. Builds on top of the [const_date_time package](https://pub.dev/packages/const_date_time).
## Getting started
Install the package:
```bash
flutter pub add const_date_time_range
```## Usage
You can use a `ConstDateTimeRange` anywhere a `DateTimeRange` is expected. All major `DateTimeRange` constructors have a `const` version.
```dart
import 'package:const_date_time/const_date_time.dart';
import 'package:const_date_time_range/const_date_time_range.dart';// const constructors
const start = ConstDateTime(2024);
const end = ConstDateTime(2025);
const constDateTimeRange = ConstDateTimeRange(start: start, end: end);
```You can access the underlying `DateTimeRange` object directly:
```dart
const cdtr = ConstDateTimeRange(start: ConstDateTime(2024), end: ConstDateTime(2025))
final DateTimeRange dtr = cdtr.dateTimeRange;
// other getters are available as well:
final ConstDateTime dtrStart = cdtr.start;
final ConstDateTime dtrEnd = cdtr.end;
final Duration dtrDur = cdtr.duration;
```You can convert a `DateTimeRange` to a `ConstDateTimeRange`.
```dart
final dtr = DateTimeRange(start: DateTime(2024), end: DateTime(2025));
final ConstDateTimeRange cdtr = dtr.toConstDateTimeRange();
```## Sponsor
Please consider [sponsoring my work](https://github.com/sponsors/westy92) to ensure this library receives the attention it deserves.
## License
const_date_time_range is released under the MIT License.