range_type

Last updated:

0 purchases

range_type Image
range_type Images
Add to Cart

Description:

range type

Range package for Dart #
The convenient pure Dart library of ranges representation. Range types are data types representing a range of values of some element type.
Examples #
Creation of a range
// common way
var range = IntRange(
lowerBound: Bound(type: BoundType.inclusive, value: 1),
upperBound: Bound(type: BoundType.exclusive, value: 10),
);

// through parsing from a string
range = IntRange.parse('[1, 10)');

// through an extension
range = 1.range(10);
copied to clipboard
Checking for an element in the range
var range = IntRange.parse('[1, 10)');

// common way
if(range.containsElement(7)) {
print('contains');
}

// through an extension
if(7.contained(range)) {
print('contains');
}
copied to clipboard
DateTime range
import 'package:range_type/predefined_ranges.dart';

void main() {
final july = DateTimeRange.parse('[2022-07-01, 2022-08-01)');

final scheduleDate1 = DateTime(2022, 07, 02);
final scheduleDate2 = DateTime(2022, 08, 07);

final workingDays = DateTimeRange.parse('[2022-07-20, 2022-08-15)');

print('Is scheduleDate1 in July? ${july.containsElement(scheduleDate1)}');
print('Is scheduleDate2 in July? ${july.containsElement(scheduleDate2)}');
print('Is workingDays overlaps? ${july.overlap(workingDays)}');
print('workingDays intersection: ${july.intersection(workingDays)}');
print('workingDays union: ${july.union(workingDays)}');
print('july difference workingDays: ${july.difference(workingDays)}');
}
copied to clipboard
Ideas #
If you have any ideas on how to enhance this package or have any concern, feel free to make an issue.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.