const_date_time_range

Build Status Code Coverage Funding Status

A drop-in replacement for Dart's DateTimeRange class with const constructors. Builds on top of the const_date_time package.

Getting started

Install the package:

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.

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:

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.

final dtr = DateTimeRange(start: DateTime(2024), end: DateTime(2025));
final ConstDateTimeRange cdtr = dtr.toConstDateTimeRange();

Please consider sponsoring my work to ensure this library receives the attention it deserves.

License

const_date_time_range is released under the MIT License.

Libraries

const_date_time_range
ConstDateTime package.